yii - curl命令行请求并不慢,但php curl_exec很慢,怎么回事?

php中文网
发布: 2016-06-06 20:06:18
原创
1948人浏览过

问题:如题。

<code class="text">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"}</code>
登录后复制
<code>    $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);
    </code>
登录后复制

但是,诡异的是,我用xdebug跟踪,其实是可以跑通的。。
有没有遇到这个问题的。求解,谢谢!

回复内容:

问题:如题。

<code class="text">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"}</code>
登录后复制
<code>    $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);
    </code>
登录后复制

但是,诡异的是,我用xdebug跟踪,其实是可以跑通的。。
有没有遇到这个问题的。求解,谢谢!

问题已找到。
原来是请求的url在php程序环境中是超时了。但xdebug或编辑器也许设了超时时间,所以能够跑通。

Getfloorplan
Getfloorplan

创建 2D、3D 平面图和 360° 虚拟游览,普通房间变成梦想之家

Getfloorplan 148
查看详情 Getfloorplan

立即学习PHP免费学习笔记(深入)”;

  1. curl一定要设置超时时间,不然不知道是不是curl超时。

  2. 诡异的问题其实是需要全面地检查来确定问题。

相关标签:
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号