Curl error: Operation timed out

curl, php

Solution

Your curl gets timed out. Probably the url you are trying that requires more that 30 seconds.

If you are running the script through browser, then set the `set_time_limit` to zero for infinite seconds.

set_time_limit(0);

Increase the curl's operation time limit using this option `CURLOPT_TIMEOUT`

curl_setopt($ch, CURLOPT_TIMEOUT,500); // 500 seconds

It can also happen for infinite redirection from the server. To halt this try to run the script with follow location disabled.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

Problem

I have the following fatal error when trying to use Curl: ``` PHP Fatal error: Uncaught HTTP_Request2_MessageException: Curl error: Operation timed out after 30000 milliseconds with 0 bytes received in /usr/share/php/HTTP/Request2/Adapter/Curl.php on line 200 Exception trace Function Location 0 HTTP_Request2_Adapter_Curl::wrapCurlError('Resource id #12') /usr/share/php/HTTP/Request2/Adapter/Curl.php:200 1 HTTP_Request2_Adapter_Curl->sendRequest(Object(HTTP_Request2)) /usr/share/php/HTTP/Request2.php:959< in /usr/share/php/HTTP/Request2/Adapter/Curl.php on line 172 ``` However, I can't see how to best debug it. There's no reference to any line of code I've written, only the `HTTP_Request2` and `Curl` modules. What's the best approach to try and resolve this?

Original source