Skip to content

Commit a795ced

Browse files
SanderMullerclaude
authored andcommitted
Show the file cache directory in diagnose, use it from PHP 8.3 only
PHP 8.3 is the oldest version the turbo extension is built for, and the range the file cache was measured on. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 74e48b7 commit a795ced

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎src/Turbo/TurboDiagnoseExtension.php‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use function php_uname;
1111
use function phpversion;
1212
use function sprintf;
13+
use function strlen;
14+
use function strpos;
15+
use function substr;
1316
use const PHP_DEBUG;
1417
use const PHP_MAJOR_VERSION;
1518
use const PHP_MINOR_VERSION;
@@ -69,9 +72,37 @@ public function print(Output $output): void
6972
'<info>Turbo trusted types:</info> %s',
7073
$this->describeTrustedTypes(),
7174
));
75+
$output->writeLineFormatted(sprintf(
76+
'<info>OPcache file cache:</info> %s',
77+
$this->describeFileCache(),
78+
));
7279
$output->writeLineFormatted('');
7380
}
7481

82+
/**
83+
* Where TurboProcessRestarter keeps the persistent OPcache file cache, so it
84+
* can be found and deleted.
85+
*/
86+
private function describeFileCache(): string
87+
{
88+
$fileCache = ini_get('opcache.file_cache');
89+
if ($fileCache !== false && $fileCache !== '') {
90+
return $fileCache;
91+
}
92+
93+
// without the restart (no pcntl), only the spawned workers get one
94+
foreach (TurboProcessRestarter::getOpcacheArgs() as $opcacheArg) {
95+
$prefix = 'opcache.file_cache=';
96+
if (strpos($opcacheArg, $prefix) !== 0 || $opcacheArg === $prefix) {
97+
continue;
98+
}
99+
100+
return sprintf('%s (spawned workers)', substr($opcacheArg, strlen($prefix)));
101+
}
102+
103+
return 'off';
104+
}
105+
75106
private function describeTrustedTypes(): string
76107
{
77108
if (TurboExtensionEnabler::isTrustingOwnTypes()) {

‎src/Turbo/TurboProcessRestarter.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use function unlink;
4343
use const PHP_BINARY;
4444
use const PHP_OS_FAMILY;
45+
use const PHP_VERSION_ID;
4546

4647
/**
4748
* Restarts the main PHPStan process via pcntl_exec() when the process it
@@ -303,7 +304,9 @@ public static function getOpcacheArgs(): array
303304
* and has no build to key the directory by. Not in CI (see
304305
* resolveContinuousIntegration()): an empty temp dir at the start of every
305306
* job would make the cache pure cost, and with a file cache the
306-
* extension's trusted-types pass is off. Not on Windows either: every
307+
* extension's trusted-types pass is off. Not on PHP older than the oldest
308+
* one the extension is built for (TurboExtensionSelector::MINIMUM_PHP_VERSION_ID):
309+
* the file cache was only measured on that range. Not on Windows either: every
307310
* spawned worker there gets its own opcache.cache_id (see ProcessHelper),
308311
* and OPcache then keeps a separate file cache per worker that no later
309312
* run reuses: 2 GB after one benchmark run on a GitHub runner, and cold
@@ -316,6 +319,9 @@ private static function getFileCacheDirectory(): ?string
316319
}
317320

318321
self::$fileCacheDirectoryResolved = true;
322+
if (PHP_VERSION_ID < TurboExtensionSelector::MINIMUM_PHP_VERSION_ID) {
323+
return null;
324+
}
319325
if (PHP_OS_FAMILY === 'Windows' || !function_exists('posix_geteuid') || !class_exists('Phar', false)) {
320326
return null;
321327
}

0 commit comments

Comments
 (0)