Menu Home

stream_socket_shutdown

osbo.com | PHP | Functions | stream_socket_shutdown

Shutdown a full-duplex connection

Syntax

stream_socket_shutdown ( resource $stream , int $how ) : bool

Parameters

stream

An open stream (opened with stream_socket_client(), for example)

how

One of the following constants:

STREAM_SHUT_RD disable further receptions
STREAM_SHUT_WR disable further transmissions
STREAM_SHUT_RDWR disable further receptions and transmissions

Return

Returns TRUE on success or FALSE on failure.

Examples

stream how

<?

$transport = "tcp";
$host = "127.0.0.1";
$port = "1234";

$socket = $transport . "://" . $host . ":" . $port;

$server = stream_socket_server($socket);
$client = stream_socket_client($socket);

    $string = "Hello";

    var_dump(fwrite($client, $string));

    $how = STREAM_SHUT_WR;

    stream_socket_shutdown($client, $how);

    var_dump(fwrite($client, $string));

fclose($client);
fclose($server);

?>
int(5)
bool(false)

Return

<?

$transport = "tcp";
$host = "127.0.0.1";
$port = "1234";

$socket = $transport . "://" . $host . ":" . $port;

$server = stream_socket_server($socket);
$client = stream_socket_client($socket);

    $how = STREAM_SHUT_WR;

    $return = stream_socket_shutdown($client, $how);

    var_export($return);

fclose($client);
fclose($server);

?>
true

PHP