Skip to content

Commit 92fd7d0

Browse files
ondrejmirtesclaude
andcommitted
Require turbo for forked workers only when running from a phar
The turbo requirement existed for the phar-fork-guard: libphar serves phar:// reads through one shared per-archive fd whose seek cursor forked children race on. Outside a phar there is nothing to guard - and no turbo is lost by forking either, because the distributed binaries only exist next to a phar, so spawned workers of a source checkout run without turbo too, while an ini-loaded extension is inherited by fork like any other. Source-checkout installs - including phpstan-src's own self-analysis - now fork their workers and skip the per-worker application re-boot. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GnwgpaeUXRkgSDyg95tfK8
1 parent a95bf57 commit 92fd7d0

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

‎src/Parallel/ForkParallelChecker.php‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Parallel;
44

5+
use Phar;
56
use PHPStan\Command\Output;
67
use PHPStan\DependencyInjection\AutowiredService;
78
use PHPStan\Diagnose\DiagnoseExtension;
@@ -18,15 +19,17 @@
1819
* process and skips the application re-boot a spawned one pays. It requires:
1920
*
2021
* - pcntl/posix functions (not available on Windows — always spawn there)
21-
* - the turbo extension, active with the expected version. A forked worker
22-
* inherits the parent's extensions, so the spawn-time `-d extension=`
23-
* injection cannot reach it — TurboProcessRestarter re-executes the main
24-
* process with the distributed binary loaded when needed. The extension
25-
* also arms the phar-fork-guard: libphar serves phar:// reads through one
26-
* shared per-archive fd whose seek cursor forked processes race on,
27-
* corrupting reads — the guard gives each forked child a private cursor.
28-
* Without it, running from a phar would corrupt analysis, so no turbo
29-
* means spawn.
22+
* - when running from a phar, the turbo extension, active with the expected
23+
* version. The extension arms the phar-fork-guard: libphar serves phar://
24+
* reads through one shared per-archive fd whose seek cursor forked
25+
* processes race on, corrupting reads — the guard gives each forked child
26+
* a private cursor. TurboProcessRestarter re-executes the main process
27+
* with the distributed binary loaded when needed (a forked worker inherits
28+
* the parent's extensions; the spawn-time `-d extension=` injection cannot
29+
* reach it). Outside a phar there is nothing to guard, and no turbo is
30+
* lost by forking either: the distributed binaries only exist next to a
31+
* phar, so spawned workers of a source checkout run without turbo too —
32+
* an ini-loaded extension is inherited by fork like any other.
3033
* - OPcache + JIT off — their shared memory is not safe to populate
3134
* concurrently from forked children and doing so corrupts analysis
3235
* results.
@@ -68,8 +71,8 @@ private function getDisabledReason(): ?string
6871
return 'pcntl/posix functions are not available';
6972
}
7073

71-
if (!TurboExtensionEnabler::isActive()) {
72-
return 'the turbo extension is not active (see the Turbo extension section)';
74+
if (Phar::running(false) !== '' && !TurboExtensionEnabler::isActive()) {
75+
return 'running from a phar without the active turbo extension (its fork guard protects phar:// reads in forked children)';
7376
}
7477

7578
if ($this->isOpcacheOrJitEnabled()) {

0 commit comments

Comments
 (0)