swoole-src
swoole-src copied to clipboard
Calling macro `swoole_fatal_error` will immediately terminate the process without executing `php_request_shutdown` in Swoole 5.1.x
With the following codes, php_request_shutdown will be called in PHP 7.4 + Swoole 4.8.x but not in PHP 8.3 + Swoole 5.1.x. Is this expected behavior?
\register_shutdown_function(static function () {
echo "register_shutdown_function called\n";
});
echo "before\n";
\Swoole\Coroutine::create(static function () {
(new \Swoole\Process(static fn() => file_get_contents('https://www.google.com')))->start();
});
echo "after\n";
\Swoole\Event::wait();
Outputs:
PHP 8.3 + 5.1.3
before
Fatal error: Uncaught Swoole\Error: must be forked outside the coroutine in /path/to/test.php:8
Stack trace:
#0 /path/to/test.php(8): Swoole\Process->start()
#1 [internal function]: {closure}()
#2 {main}
thrown in /path/to/test.php on line 8
PHP 7.4 + Swoole 4.8.13
before
PHP Fatal error: Uncaught Swoole\Error: must be forked outside the coroutine in /path/to/test.php:8
Stack trace:
#0 /path/to/test.php(8): Swoole\Process->start()
#1 {main}
thrown in /path/to/test.php on line 8
register_shutdown_function called
In coroutines, fork or Swoole\Process cannot be used, otherwise the coroutine context will be duplicated.
In coroutines, fork or Swoole\Process cannot be used, otherwise the coroutine context will be duplicated.
The above example is intended to trigger swoole_fatal_error to demonstrate the issue.
The swoole_fatal_error is triggered, which indicates that it is not a runtime error, there is a problem with your code, you must modify the code.
swoole_fatal_error cannot be caught, and the program will exit immediately.