PHPcurl_exec() 挂起
我使用此函数发出 cURL 请求:
function curl_request($options) //single custom cURL request.
{
$ch = curl_init();
$options[CURLOPT_FOLLOWLOCATION] = true;
$options[CURLOPT_COOKIEJAR] = 'cookies.txt';
$options[CURLOPT_COOKIEFILE] = 'cookies.txt';
$options[CURLINFO_HEADER_OUT] = true;
$options[CURLOPT_VERBOSE] = true;
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_CONNECTTIMEOUT] = 5;
$options[CURLOPT_TIMEOUT] = 5;
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
脚本有时(但并非总是)挂在 $response = curl_exec($ch)
行上。即使 PHP 脚本设置为无限超时(在客户端,Firebug 将其视为“已中止”),也会发生这种情况。错误日志中没有任何内容。它只是在挂起时没有超过该行。
可能发生什么事?有什么建议吗?
I use this function to make cURL requests:
function curl_request($options) //single custom cURL request.
{
$ch = curl_init();
$options[CURLOPT_FOLLOWLOCATION] = true;
$options[CURLOPT_COOKIEJAR] = 'cookies.txt';
$options[CURLOPT_COOKIEFILE] = 'cookies.txt';
$options[CURLINFO_HEADER_OUT] = true;
$options[CURLOPT_VERBOSE] = true;
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_CONNECTTIMEOUT] = 5;
$options[CURLOPT_TIMEOUT] = 5;
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
The script hangs sometimes, but not always, on the $response = curl_exec($ch)
line. This occurs even when the PHP script is set with infinite timeout (on the client side, Firebug takes this as "Aborted"). There is nothing in the error log.. It just doesn't get past that line when it hangs.
What could be going on? Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎是服务器的资源。当我切换到具有更高带宽限制的更好的网络主机时,一切正常。
The issue seems to have been the resources of the server. When I switched to a better web host with a higher bandwidth limit things worked fine.