Example 1 — Shutdown Write on a Pair
Write a message, shut down writing, and let the other end read then hit EOF.
<?php
$pair = stream_socket_pair(STREAM_PF_INET, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
[$a, $b] = $pair;
fwrite($a, 'bye');
stream_socket_shutdown($a, STREAM_SHUT_WR);
echo fread($b, 3), PHP_EOL;
$more = fread($b, 1);
echo $more === '' || $more === false ? 'eof' : 'data', PHP_EOL;
fclose($a);
fclose($b); How It Works
- Send bye on end $a.
- STREAM_SHUT_WR signals that $a will send no more.
- End $b still reads the buffered bytes.
- A later read sees end-of-file behavior.

