cURL Timeout controls for how many seconds or milliseconds a connection should be made available for transfer of data. Default Timeout for cURL is 0, which mean that cURL will not close connection while the data is transferring. Here one should remember that while default timeout is 0 the PHP also impose a time limit on script execution, which is default to 30 seconds. So if the cURL transfer took more than 30 seconds PHP will force fully close the script execution. If the cURL required more time to complete task consider setting
set_time_limit(0)
on top of the PHP script.
cURL Timeout PHP
//set_time_limit(0); //If cURL requried more that 30 seconds, 0 mean no Timeout Limit. Limit is set in seconds.
$ch= curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.tutorialjinni.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);// TIMEOUT IN SECONDS
//curl_setopt($ch, CURLOPT_TIMEOUT_MS, 30);// TIMEOUT IN MILLISECONDS
$data=curl_exec($ch);
curl_close($ch);
echo $data
cURL Timeout Example Shell
curl --connect-timeout 20 "https://www.tutorialjinni.com"