2

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?

3
  • CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE pointing to the same file? you're sure this is what you want? For testing I would just comment these two lines to prevent a deadlock because of file access. Commented Jul 20, 2011 at 21:06
  • The thing is the request requires cookies to work Commented Jul 20, 2011 at 21:07
  • 1
    yeah sure, but just for debugging. Alternatively monitor the network traffic and report what's happening in case the script hangs. Commented Jul 20, 2011 at 21:10

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.