Once a fatal error occurs during the running of swoole_serverServer, the client connection will not be responded to.
For example, a web server, if there is a fatal error, an HTTP 500 error message should be sent to the client. (Recommended study: swoole video tutorial)
In PHP, fatal errors can be captured through register_shutdown_function error_get_last 2 functions, and the error information is sent to the client connection.
The specific code examples are as follows:
register_shutdown_function('handleFatal'); function handleFatal() { $error = error_get_last(); switch ($error['type'] ?? null) { case E_ERROR : case E_PARSE : case E_CORE_ERROR : case E_COMPILE_ERROR : $message = $error['message'] . PHP_EOL; if (isset($_SERVER['REQUEST_URI'])) { $message .= '[QUERY] ' . $_SERVER['REQUEST_URI']; } // log or send: // error_log($message); // $server->send($fd, $message); break; } }
The above is the detailed content of How to catch php errors with swoole. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools
