forked from kriswallsmith/spork
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#7: Do not execute parent's shutdown function in child process
- Loading branch information
Showing
2 changed files
with
14 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Spork, an OpenSky project. | ||
* This file is part of the thelevti/spork package. | ||
* | ||
* (c) OpenSky Project Inc | ||
* (c) Petr Levtonov <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spork; | ||
|
||
use InvalidArgumentException; | ||
|
@@ -95,6 +97,7 @@ public function fork($callable) | |
} | ||
|
||
if (0 === $pid) { | ||
$currPid = posix_getpid(); | ||
// reset the list of child processes | ||
$this->forks = []; | ||
|
||
|
@@ -103,8 +106,11 @@ public function fork($callable) | |
$message = new ExitMessage(); | ||
|
||
// phone home on shutdown | ||
register_shutdown_function(function () use ($shm, $message): void { | ||
$status = null; | ||
register_shutdown_function(function () use ($currPid, $shm, $message): void { | ||
// Do not execute this function in child processes. | ||
if ($currPid !== posix_getpid()) { | ||
return; | ||
} | ||
|
||
try { | ||
$shm->send($message, false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Spork, an OpenSky project. | ||
* This file is part of the thelevti/spork package. | ||
* | ||
* (c) OpenSky Project Inc | ||
* (c) Petr Levtonov <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spork; | ||
|
||
use Exception; | ||
|