swoole What is the fatal error?
Capture fatal errors during Server runtime
Once a fatal error occurs during Server runtime, the client connection will not be able to receive a response. For example, a web server should send an HTTP 500 error message to the client if there is a fatal error.
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 What does swoole fatal error mean?. For more information, please follow other related articles on the PHP Chinese website!