dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.64k stars 218 forks source link

Proposal: remove automatic exceptions handling #41

Closed dunglas closed 1 year ago

dunglas commented 1 year ago

Currently, in worker mode, FrankenPHP automatically catches exceptions: https://github.com/dunglas/frankenphp/blob/main/frankenphp.c#L187-L196

Exceptions would be better handled in userland. This would simplify Franken's PHP code and make its behavior more predictable. AFAIK, other runtimes with a worker mode (RoadRunner) don't automatically handle exceptions as well.

Symfony never throws in worker mode: https://github.com/symfony/symfony/pull/45997

WDYT @Nyholm, as you have a good experience of what is expected in these cases?

Nyholm commented 1 year ago

I dont think you should catch exceptions. Sure the process crash, but that is also a super convenient way to repair from unexpected errors.

I have some bad scenarios where symfony share resources between requests (like DB connection), things crash (db is gone) and we dont reset our services properly (ie read the new DB DSN). I would much much rather have slow responses and not reuse resources when unexpected things happens.

From the runtime point of view. If the application did not catch an exception, the runtime would like to find out and decide if the kernel should be restarted or not. (Bref example)

Reference: https://github.com/php-runtime/frankenphp-symfony/blob/0.1.0/src/Runner.php#L26

dunglas commented 1 year ago

That makes sense, I'll remove this code. Thank you @Nyholm