yii - curl命令列請求並不慢,但php curl_exec很慢,怎麼回事?

來源:互聯網
上載者:User
關鍵字 curl php yii
問題:如題。

curl "http://xxx.com.cn/api/open" --data "access_token=4CC7D18986B8987663E57F3CA0A87198&once=cSTvPM2h9lts&timestamp=1464951645705&sign=2da0302f6aa7b01a5cfa964d818109df&version=1.0&format=JSON&sign_type=MD5&attach=&method=open.jewelStatus.modify&data="%"7B"%"22orderId"%"22"%"3A"%"22413"%"22"%"2C"%"22status"%"22"%"3A100"%"2C"%"22operation"%"22"%"3A2"%"7D" --compressed% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed 100   400    0   118  100   282     77    184  0:00:01  0:00:01   --:--:--   186{"attach":"","errmsg":"","result":"{}","sign":"0ec35efd5c6500baa566937950a9cb40","status":"1000","timestamp":"1465006446020"}
    $url = Yii::$app->params['erp_api']['url'];    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // post資料    curl_setopt($ch, CURLOPT_POST, 1);    // post的變數    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);    $output = curl_exec($ch);//**<=Maximum execution time of 30 seconds exceeded**    curl_close($ch);    

但是,詭異的是,我用xdebug跟蹤,其實是可以跑通的。。
有沒有遇到這個問題的。求解,謝謝!

回複內容:

問題:如題。

curl "http://xxx.com.cn/api/open" --data "access_token=4CC7D18986B8987663E57F3CA0A87198&once=cSTvPM2h9lts&timestamp=1464951645705&sign=2da0302f6aa7b01a5cfa964d818109df&version=1.0&format=JSON&sign_type=MD5&attach=&method=open.jewelStatus.modify&data="%"7B"%"22orderId"%"22"%"3A"%"22413"%"22"%"2C"%"22status"%"22"%"3A100"%"2C"%"22operation"%"22"%"3A2"%"7D" --compressed% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed 100   400    0   118  100   282     77    184  0:00:01  0:00:01   --:--:--   186{"attach":"","errmsg":"","result":"{}","sign":"0ec35efd5c6500baa566937950a9cb40","status":"1000","timestamp":"1465006446020"}
    $url = Yii::$app->params['erp_api']['url'];    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // post資料    curl_setopt($ch, CURLOPT_POST, 1);    // post的變數    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);    $output = curl_exec($ch);//**<=Maximum execution time of 30 seconds exceeded**    curl_close($ch);    

但是,詭異的是,我用xdebug跟蹤,其實是可以跑通的。。
有沒有遇到這個問題的。求解,謝謝!

問題已找到。
原來是請求的url在php程式環境中是逾時了。但xdebug或編輯器也許設了逾時時間,所以能夠跑通。

  1. 用curl一定要設定逾時時間,不然不知道是不是curl逾時。

  2. 詭異的問題其實是需要全面地檢查來確定問題。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.