php-go icon indicating copy to clipboard operation
php-go copied to clipboard

Forking PHP while module is loaded causes deadlocks

Open SpencerMalone opened this issue 6 years ago • 2 comments

I don't think (based on issues found in the golang repository) that we will see golang support for forking in shared c libraries anytime soon. If you fork and interact with golang objects and functions post-fork, you will eventually deadlock.

For example, in the current example.php:

Take...

test_funcs();
test_classes();
test_inis();

And rewrite it work a fork, based on the example @ https://www.php.net/manual/en/function.pcntl-fork.php

test_funcs();
$pid = pcntl_fork();
if ($pid == -1) {
     die('could not fork');
} else if ($pid) {
     // we are the parent
     pcntl_wait($status); //Protect against Zombie children
} else {
    $i=0;
    while(true) {
    test_classes();
    echo($i++);
    }
}

test_inis();

And you will see fairly quickly, it will deadlock. Here is a GIF: Screen Capture on 2019-05-23 at 22-04-29

Knowing that this probably won't fixable anytime soon, and from what I can tell, PHP doesn't offer support for unloading and reloading extensions during forking, maybe we should put up a notice about it in the README? Unless anybody know of a theoretical way around this, which I would be very grateful for.

SpencerMalone avatar May 24 '19 02:05 SpencerMalone

The project seems to have been no longer maintained by the author.

xywf221 avatar Jun 05 '19 04:06 xywf221

You can load extensions at runtime using dl() within child, just remove extension from php.ini

Note that dl() will not be available in ZTS builds (if php-go gets around to it for php7) and PHP-FPM doesn't allow dl().

ClosetGeek-Git avatar Jul 20 '19 04:07 ClosetGeek-Git