Question

In my script i use this function:

function url_exists($url) {
 if ((strpos($url, "http")) === false) $url = "http://" . $url;
 if (is_array(@get_headers($url)))
      return true;
 else
      return false;
}

How can i set the time limit of execute function @get_headers? I need function like set_time_limit() by works for one function, not for whole script.

Was it helpful?

Solution

The function get_headers() doesn't supports a timeout or a context param. Try:

ini_set('default_socket_timeout', YOUR_VALUE_IN_SECONDS);

This will set the default timeout to a value of your choice. Don't forget to reset the timeout after the operation has finished.

OTHER TIPS

You can set it with ini setting or by creating default context values for streams:

stream_context_set_default(array(
    'http' => array('timeout' => 10) // in seconds
));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top