socket_set_timeout()
socket_set_timeout() — Alias of stream_set_timeout().
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
socket_set_timeout() is an alias of stream_set_timeout(): same parameters, same return value.
Signature
socket_set_timeout(resource $stream, int $seconds, int $microseconds = 0): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $stream | resource | The target stream. |
| $seconds | int | The seconds part of the timeout to be set. |
| $microseconds | int | The microseconds part of the timeout to be set. |
Return value
Returns true on success or false on failure.
Example
A runnable snippet:
$fp = fsockopen("www.example.com", 80); if (!$fp) { echo "Unable to open\n"; } else { fwrite($fp, "GET / HTTP/1.0\r\n\r\n"); stream_set_timeout($fp, 2); $res = fread($fp, 2000); $info = stream_get_meta_data($fp); fclose($fp); if ($info['timed_out']) { echo 'Connection timed out!'; } else { echo $res; } }
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page socket_set_timeout() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.