stream_socket_shutdown()
stream_socket_shutdown() — Shutdown a full-duplex connection.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.2.1, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Shutdowns (partially or not) a full-duplex connection.
Signature
stream_socket_shutdown(resource $stream, int $mode): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $stream | resource | An open stream (opened with stream_socket_client(), for example) |
| $mode | int | One of the following constants: STREAM_SHUT_RD (disable further receptions), STREAM_SHUT_WR (disable further transmissions) or STREAM_SHUT_RDWR (disable further receptions and transmissions). |
Return value
Returns true on success or false on failure.
Example
A runnable snippet:
$server = stream_socket_server('tcp://127.0.0.1:1337'); $client = stream_socket_client('tcp://127.0.0.1:1337'); var_dump(fputs($client, "hello")); stream_socket_shutdown($client, STREAM_SHUT_WR); var_dump(fputs($client, "hello")); // doesn't work now
Output:
int(5) Notice: fputs(): send of 5 bytes failed with errno=32 Broken pipe in test.php on line 9 int(0)
Changelog
| Version | Change |
|---|---|
| 8.0.0 | Now throws a ValueError if mode is invalid. Previously, an E_WARNING was raised and false was returned. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page stream_socket_shutdown() (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.