How to set timeout for get_meta_tags() & get_headers()

The get_headers and get_meta_tags function use the default HTTP Stream Wrapper underneath. You can either change the ini setting as shown elsewhere on this page or modify the behavior of that wrapper and set a specific timeout:

stream_context_set_default(
    array(
        'http' => array(
            'timeout' => 5
        )
    )
);

Note that changing the default HTTP Stream Context will apply to all functions using it. If you want to restore the timeout to the original default settings, do:

$originalDefaults = stream_context_set_default( … );
$meta = get_meta_tags( … );
stream_context_set_default($originalDefaults);

On a sidenote, if you call any functions using an HTTP Stream Wrapper, PHP will also automatically populate the variable $http_response_header in the current scope, so you don't have to call get_headers in addition, e.g.

$originalDefaults = stream_context_set_default( … );
$meta = get_meta_tags( … );
stream_context_set_default($originalDefaults);
var_dump($http_response_header);

You should be able to influence this (as it's via URL wrappers) with the default_socket_timeout ini setting.

Try either setting it in the php.ini file or by doing something like

ini_set('default_socket_timeout', 10);

to set a 10 sec timeout (the default value is 60)