40秒后CURL得到500错误

I set all options with timeout and set_time_limit, but it's not help. CURL get 500 error after 40 seconds. On remote server start long process and I need a wait finish. If file is small - all ok, if file is big - get 500 error after 40 seconds. This my code:

$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);

A HTTP500 error indicates that there is a SEVER side error.

Check the web server(Apache?) or application server(Php?) logs in order to be able to debug the issue.

HTTP500 status explained: http://www.checkupdown.com/status/E500.html

I realize this is old and the poster likely isn't having the same issue but:

To troubleshoot HTTP 500 errors read over your apache error log file.

If you are receiving an HTTP500 after 40s then likely the error in your log file is "mod_fcgid: read data timeout in 40 seconds" which is resolved not by increasing your PHP Execution Timeout but increasing FcgidIOTimeout which defaults to 40 seconds.

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

This can be done by adding / modifying the following line your fcgid.conf file.

FcgidIOTimeout 120