Handling socket errors

suggest change

socket_last_error returns the code for the last error from the sockets extension. Pass a socket to read the error stored on that socket. socket_strerror turns the code into a message.

Since PHP 8.0 a socket is a Socket object, not a resource. is_resource() is false for that object.

function onSocketFailure(string $message, $socket = null) {
    if ($socket instanceof \Socket || is_resource($socket)) {
        $message .= ": " . socket_strerror(socket_last_error($socket));
    }
    die($message);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents