【发布时间】:2011-10-09 18:04:53
【问题描述】:
我使用这个函数来发出 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 将其视为“已中止”),也会发生这种情况。错误日志中没有任何内容。它只是挂起时没有超过该行。
会发生什么?有什么建议吗?
【问题讨论】:
-
CURLOPT_COOKIEJAR和CURLOPT_COOKIEFILE指向同一个文件?你确定这是你想要的吗?为了进行测试,我只需注释这两行以防止由于文件访问而导致死锁。 -
问题是请求需要 cookie 才能工作
-
是的,但只是为了调试。或者监控网络流量并报告脚本挂起时发生的情况。