Handling socket errors
suggest changesocket_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);
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents