40秒后CURL得到500错误

时间:2016-08-17 12:27:12

标签: php curl timeout

我使用timeout和set_time_limit设置所有选项,但它没有帮助。 40秒后CURL得到500错误。在远程服务器上启动漫长的过程,我需要等待完成。如果文件很小 - 一切正常,如果文件很大 - 40秒后得到500错误。这是我的代码:

$curl = curl_init("http://example.com/index.php?page=uploads");
    curl_setopt($curl, CURLOPT_POST, 1);
    $datas = array(
        "id" => $id,
        "video" => $filename->new_file_name,
        "title" => $_POST["title"],
        "description" => $_POST["description"],
        "category" => array($_POST["category"]),
        "location" => $_POST["location"],
        "check" => $check,
        "start" => $start,
        "duration" => $duration
    );
    $data = json_encode($datas);

    $fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_setopt($curl, CURLOPT_STDERR, $fp);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
    curl_setopt($curl, CURLOPT_TIMEOUT_MS, 900000);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
    curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($curl, curl_exec, 0);
    curl_exec($curl);
    print_r(curl_getinfo($curl));
    curl_close($curl);

2 个答案:

答案 0 :(得分:0)

HTTP500错误表示存在SEVER方错误。

检查Web服务器(Apache?)或应用程序服务器(Php?)日志,以便能够调试问题。

HTTP500状态说明:http://www.checkupdown.com/status/E500.html

答案 1 :(得分:0)

我意识到这很旧,发布者可能没有相同的问题,但是:

要解决HTTP 500错误,请读取您的apache错误日志文件。

如果40秒钟后收到HTTP500,则日志文件中的错误很可能是“ mod_fcgid:40秒内读取数据超时”,这不是通过增加PHP执行超时来解决,而是通过增加FcgidIOTimeout(默认为40秒)来解决。 / p>

http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidiotimeout

这可以通过在fcgid.conf文件中添加/修改以下行来完成。

FcgidIOTimeout 120