Skip to content

Commit 47e7e29

Browse files
committed
Keep the composed ini when a forked worker ends
Forked workers inherited the shutdown function deleting the composed ini, so the first one to end deleted it while PHP processes spawned later in the run still read their configuration from it through PHPRC. Amp-Thread-ID: https://ampcode.com/threads/T-01a17e3b-9bb8-77b1-a5c1-722d8ade601b
1 parent 119fcc3 commit 47e7e29

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/Process/Restart/RestartManager.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,14 @@ private static function cleanUpComposedIni(): void
369369
// descendants must not delete the file their siblings are still reading
370370
putenv(self::TEMPORARY_INI_ENV_VARIABLE);
371371

372-
register_shutdown_function(static function () use ($temporaryIni): void {
372+
// pcntl_fork()ed workers inherit this shutdown function; the first one
373+
// to end would delete the ini while the rest of the run still reads it
374+
$ownerPid = getmypid();
375+
register_shutdown_function(static function () use ($temporaryIni, $ownerPid): void {
376+
if (getmypid() !== $ownerPid) {
377+
return;
378+
}
379+
373380
@unlink($temporaryIni);
374381
});
375382

0 commit comments

Comments
 (0)