mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
docs(worker): Prefer try-catch over set_exception_handler (#1897)
This commit is contained in:
committed by
GitHub
parent
219a5407ff
commit
ab1ec71d24
@@ -78,9 +78,15 @@ $myApp->boot();
|
||||
|
||||
// Handler outside the loop for better performance (doing less work)
|
||||
$handler = static function () use ($myApp) {
|
||||
// Called when a request is received,
|
||||
// superglobals, php://input and the like are reset
|
||||
echo $myApp->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
|
||||
try {
|
||||
// Called when a request is received,
|
||||
// superglobals, php://input and the like are reset
|
||||
echo $myApp->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
|
||||
} catch (\Throwable $exception) {
|
||||
// `set_exception_handler` is called only when the worker script ends,
|
||||
// which may not be what you expect, so catch and handle exceptions here
|
||||
(new \MyCustomExceptionHandler)->handleException($exception);
|
||||
}
|
||||
};
|
||||
|
||||
$maxRequests = (int)($_SERVER['MAX_REQUESTS'] ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user