Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling macro swoole_fatal_error will immediately terminate the process without executing php_request_shutdown in Swoole 5.1.x #5385

Closed
Appla opened this issue Jun 27, 2024 · 3 comments
Labels

Comments

@Appla
Copy link
Contributor

Appla commented Jun 27, 2024

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
@NathanFreeman
Copy link
Member

In coroutines, fork or Swoole\Process cannot be used, otherwise the coroutine context will be duplicated.

@Appla
Copy link
Contributor Author

Appla commented Jun 29, 2024

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.

@matyhtf
Copy link
Member

matyhtf commented Jul 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants