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

socket_strerror

Description

The socket_strerror of Sockets for PHP return a string describing a socket error.

Syntax

socket_strerror(
    int $error_code
): string

Parameters

error_code

A valid socket error number, likely produced by socket_last_error().

Return

Returns the error message associated with the error_code parameter.

Examples

1 · error_code · socket_create

<?

$domain = AF_INET;
$type = SOCK_RDM;
$protocol = 0;

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

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

        $return = socket_strerror($error_code);

        die("$return");
    }

socket_close($socket);

?>
Socket type not supported

2 · error_code · socket_bind

<?

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

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

    $address = '127.0.0.1';
    $port = 80;

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

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

        $return = socket_strerror($error_code);

        die("$return");
    }

socket_close($socket);

?>
Permission denied
HomeMenu