Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

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
));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top