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

socket_set_nonblock

Description

The socket_set_nonblock of Sockets for PHP sets nonblocking mode for file descriptor fd.

Syntax

socket_set_nonblock(
    Socket $socket
): bool

Parameters

socket

A Socket instance created with socket_create() or socket_accept().

Return

Returns true on success or false on failure.

Examples

1 · socket · socket_create

<?

$domain = AF_INET;
$type = SOCK_STREAM;
$protocol = SOL_TCP;

$socket = socket_create($domain, $type, $protocol);

    if($socket === false)
    {
        $error_code = socket_last_error();

        $socket_strerror = socket_strerror($error_code);

        die("socket_create: $socket_strerror");
    }

    $address = '127.0.0.1';

    $socket_bind = socket_bind($socket, $address);

    if($socket_bind === false)
    {
        $error_code = socket_last_error($socket);

        $socket_strerror = socket_strerror($error_code);

        die("socket_bind: $socket_strerror");
    }

    $socket_listen = socket_listen($socket);

    if($socket_listen === false)
    {
        $error_code = socket_last_error($socket);

        $socket_strerror = socket_strerror($error_code);

        die("socket_listen: $socket_strerror");
    }

    $return = socket_set_nonblock($socket);

    var_export($return);

socket_close($socket);

?>
true

2 · socket · socket_create_listen

<?

$port = 5000;

$socket = socket_create_listen($port);

    if($socket === false)
    {
        $error_code = socket_last_error();

        $socket_strerror = socket_strerror($error_code);

        die("socket_create_listen: $socket_strerror");
    }

    $return = socket_set_nonblock($socket);

    var_export($return);

socket_close($socket);

?>
NOTICE[1024] unnecessary to divide by one
HomeMenu