Skip to content

Forking PHP while module is loaded causes deadlocks #47

@SpencerMalone

Description

@SpencerMalone

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions