0

I want to call a certain URL in my PHP script and if I do not get a response after 10s, the script should just continue. Does anyone knows how I can do that?

I only found two ways. One is fopen(), which determinates my script if it doesn't get a return and curl which is just calling the URL without waiting/getting response?

But how can I say, try to get the content of the URL and if you do not get anything after 10s then continue and ignore the URL?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Fraze Jr.
  • 143
  • 1
  • 2
  • 10
  • 2
    Possible duplicate of [Setting Curl's Timeout in PHP](http://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php) – Yury Fedorov Mar 10 '17 at 20:20

1 Answers1

1

You can use curl.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);

If timeout is occurred - $response variable has boolean 'false' value.

mk_
  • 179
  • 1
  • 4