Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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
));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top