Skip to content
Advertisement

If page load time takes too long

I have a curl script that I would like to wrap in an if condition to proceed anyway if the page isnt loading. Is it possible to check page load time > if taking too long > proceed anyway?

if(pageLoad != TooMuchTime {
  //Curl script to some url
} else {
  //Took to long to get a responce
}

The reason I do this is because I use a curl request as part of an install script (to track installs) the curl call is to a php file which inserts data to the database. If for any reason (network congestion, site down, ect.) the page doesn’t load I want the user to still be able to install the product.

Advertisement

Answer

Curl offers options to achieve the desired action, There is no need for if conditions.

CURLOPT_CONNECTTIMEOUT – The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. CURLOPT_TIMEOUT – The maximum number of seconds to allow cURL functions to execute.

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement