代码之家  ›  专栏  ›  技术社区  ›  Ali Mammadov

使用cronjob捕获Paypal订单

  •  0
  • Ali Mammadov  · 技术社区  · 2 年前

    正如我在标题中提到的,我试图在满足条件后用cronjob文件捕获paypal交易。想象一下有25个订单(所有订单都已授权等待捕获),现在我需要捕获它们。我用过 curl cronjob 为了让它自动运行。但实际情况是,这个过程使服务器超载,而且可能需要太多时间才能完成(例如,如果有250个订单)。我只是想问一下,也许有一种更简单的方法来实现它。我做错了吗?cronjob php文件代码如下:

      function get_content($URL){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_URL, $URL);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }
        
        if ($db->total_records($rs) > 0) {//this is the condition which we are checking here
            while($resultset = $db->fetch($rs)){ 
        
          $data =  get_content('https://'.$_SERVER['SERVER_NAME'].'/api/paypal/paypal_acts.php?capture_order_id='.$resultset['id']);
        $data = json_decode($data);
        $status =  $data->status;
        
        if ($status === 'COMPLETED' ) {
                    // success 
                    //we are inserting the data into the DB and so on.. 
    }
    

    所有的工作流程都是这样的,比如说有5个订单。需要3-5秒才能完成。我只是想象一下,如果订单超过100个,需要多少钱?应该有很多方便的方法。我无法立即捕获,因为我需要在捕获订单之前验证一些内容。

    1 回复  |  直到 2 年前
        1
  •  1
  •   Preston PHX    2 年前

    你所描述的对于批量捕获这么多订单来说是完全正常的。

    事实上,PayPal建议你在每次通话之间睡眠5秒(5000毫秒),因为有速率限制。