Repository navigation
Restart once for Turbo, OPcache and Xdebug - #6769
Open
SanderMuller wants to merge 3 commits into
Open
SanderMuller wants to merge 3 commits into
SanderMuller wants to merge 3 commits into
Conversation
When Xdebug, pcov or tideways has to go, TurboProcessRestarter now hands its -d entries to ProcessRestarter. That writes the ini without those extensions and replaces the process with pcntl_exec(), so the process restarts once, before the console application starts. Before, PHPStan exec'd for Turbo, booted to CommandHelper with Xdebug still loaded, spawned a child without Xdebug, and that child exec'd again for Turbo. Nobody waits for the exec, so the main process removes the ini on shutdown. Without pcntl, CommandHelper still restarts in a child. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Nobody waits for the exec, so a forked process takes the role of the waiting parent of a proc_open() restart. It ignores Ctrl-C, outlives the main process and then removes the ini. Before, a shutdown function removed it, which did not run when a signal ended the process. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
XdebugHandler prints "Process restarting" under XDEBUG_HANDLER_DEBUG in doRestart(), which the exec skips. The pcov e2e jobs look for that line. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With Xdebug, pcov or tideways loaded, PHPStan now restarts once, before the console application starts. This is the follow-up that #6757 (comment) describes.
Before this change, a run with Xdebug loaded did this:
TurboProcessRestarterexec'd the process for Turbo and OPcache. Xdebug was still loaded.CommandHelper::begin()and started a child process without Xdebug through xdebug-handler.-dentries, so it exec'd again for Turbo and OPcache.Now
TurboProcessRestartermakes the decision at the top ofbin/phpstan, without the autoloader:-dentries toProcessRestarter. The process is replaced anyway, so the late autoloader does not matter.pcntl_execreplaces the process with the Turbo, OPcache and marker entries on the command line. The command-lineopcache.enable_cli=1overrides theopcache.enable_cli=0that xdebug-handler writes into its ini.ProcessRestarterprints the same "Process restarting" lines as xdebug-handler underXDEBUG_HANDLER_DEBUG. The pcov e2e jobs check for them.CommandHelperstill callscheck(). In the restarted process it reads the restart settings, so the--debugnote about the restart still shows. Without pcntl, it is still the fallback that restarts in a child process.restartIfSuitable()gets two optional parameters,$autoloadPathand$appName. Rector can then do the same restart with one call:restartIfSuitable($argv, $phpstanPhar, null, 'rector'). Rector's own XdebugHandler then sees the restart and does nothing.I tested the restart paths with a 2.3.x phar (807d030f6) that has these files patched in, on macOS with Homebrew PHP 8.5 and Xdebug 3.5:
bin/phpstanand for avendor/bin/phpstanproxy.--xdebug,PHPSTAN_ALLOW_XDEBUG=1andxdebug.mode=offkeep Xdebug, as before.pcntl_execorpcntl_forkindisable_functions, the oldCommandHelperrestart runs, and the worker gets Turbo without Xdebug.CPU time (user + sys) of a small run with Xdebug loaded, median of 10 interleaved runs: 1.14 s before, 0.69 s after. The saving is in the startup, so I expect about the same absolute saving on a larger run, but I measured only small runs.
I could not test pcov and tideways locally. The pcov e2e jobs cover pcov.
🤖 Generated with Claude Code