-3

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.

DrCustUmz
  • 378
  • 4
  • 18
  • you can use [curl_getinfo](https://www.php.net/manual/en/function.curl-getinfo.php), but if the page loaded why does it matter how long it took? curl has options to timeout, set it to *TooMuchTime* and handle the error.. else our need make 2 requests which is not ideal – Lawrence Cherone Jun 13 '20 at 15:05
  • 1
    Maybe https://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php is a good thread to look at? – user3783243 Jun 13 '20 at 15:06
  • Curl has options that control a variety of timeouts. Set the ones you're interested in and handle the error. – Peter Jun 13 '20 at 15:09
  • I updated the OP to include how I use this, and why I want such a feature. Maybe then someone would have an alternative solution for me. – DrCustUmz Jun 13 '20 at 22:11
  • Thank you @user3783243 that helped – DrCustUmz Jun 13 '20 at 22:14

1 Answers1

0

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
DrCustUmz
  • 378
  • 4
  • 18