Ben G
Ben G

Reputation: 26751

PHP curl_exec() hangs

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?

Upvotes: 2

Views: 1224

Answers (1)

Ben G
Ben G

Reputation: 26751

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.

Upvotes: 3

Related Questions