Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP curl timeout error detection

People also ask

How to handle Curl timeout in php?

To set a timeout for a Curl command, you can use the --connect-timeout parameter to set the maximum time in seconds that you allow Curl to connect to the server, or the --max-time (or -m) parameter for the total time in seconds that you authorize the whole operation.

How do I check my Curl timeout?

Tell curl with -m / --max-time the maximum time, in seconds, that you allow the command line to spend before curl exits with a timeout error code (28). When the set time has elapsed, curl will exit no matter what is going on at that moment—including if it is transferring data. It really is the maximum time allowed.

What is the default Curl timeout PHP?

CURLOPT_CONNECTTIMEOUT: Defaults to 300 seconds. CURLOPT_CONNECTTIMEOUT_MS: No default. CURLOPT_ACCEPTTIMEOUT_MS: Defaults to 60000 ms.


Use curl_errno()

Code 28 is timeout.


you can check error number and its' description like this:

// Check if any error occurred
if(curl_errno($ch))
{
    echo 'Curl error: ' . curl_error($ch);
}