【问题标题】:PHP curl_exec() hangsPHP curl_exec() 挂起
【发布时间】: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_COOKIEJARCURLOPT_COOKIEFILE 指向同一个文件?你确定这是你想要的吗?为了进行测试,我只需注释这两行以防止由于文件访问而导致死锁。
  • 问题是请求需要 cookie 才能工作
  • 是的,但只是为了调试。或者监控网络流量并报告脚本挂起时发生的情况。

标签: php curl libcurl


【解决方案1】:

问题似乎是服务器的资源。当我切换到具有更高带宽限制的更好的网络主机时,一切正常。

【讨论】:

    猜你喜欢
    • 2011-09-12
    • 1970-01-01
    • 2013-07-19
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多