HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

stream_socket_shutdown

Description

The stream_socket_shutdown of Stream for PHP 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_RDdisable further receptions
STREAM_SHUT_WRdisable further transmissions
STREAM_SHUT_RDWRdisable further receptions and transmissions

Return

Returns TRUE on success or FALSE on failure.

Examples

1 · 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)

2 · 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);