Example 1 — Set a Five-Second Timeout
Apply a timeout on a php://temp stream and print the boolean result.
<?php
$stream = fopen('php://temp', 'r+');
$ok = socket_set_timeout($stream, 5, 0);
var_dump($ok);
fclose($stream); How It Works
- fopen('php://temp') gives a safe offline stream.
- socket_set_timeout() is an alias of stream_set_timeout().
- 5 seconds and 0 microseconds become the wait limit.
- true means PHP accepted the setting.

