0

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.

2 Answers2

0

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.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
0

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
));
dev-null-dweller
  • 29,274
  • 3
  • 65
  • 85