Skip to content

Commit eda5320

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 6a0b264 commit eda5320

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎src/Process/Restart/OpcacheSettings.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use function trim;
3939
use function unlink;
4040
use const PHP_OS_FAMILY;
41+
use const PHP_VERSION_ID;
4142

4243
/**
4344
* The OPcache configuration PHPStan runs with: the restart activates it for
@@ -183,7 +184,9 @@ public static function getIniEntries(): array
183184
* and has no build to key the directory by. Not in CI (see
184185
* resolveContinuousIntegration()): an empty temp dir at the start of every
185186
* job would make the cache pure cost, and with a file cache the
186-
* extension's trusted-types pass is off. Not on Windows either: every
187+
* extension's trusted-types pass is off. Not on PHP older than the oldest
188+
* one the extension is built for (TurboExtensionSelector::MINIMUM_PHP_VERSION_ID):
189+
* the file cache was only measured on that range. Not on Windows either: every
187190
* spawned worker there gets its own opcache.cache_id (see ProcessHelper),
188191
* and OPcache then keeps a separate file cache per worker that no later
189192
* run reuses: 2 GB after one benchmark run on a GitHub runner, and cold
@@ -196,6 +199,9 @@ private static function getFileCacheDirectory(): ?string
196199
}
197200

198201
self::$fileCacheDirectoryResolved = true;
202+
if (PHP_VERSION_ID < TurboExtensionSelector::MINIMUM_PHP_VERSION_ID) {
203+
return null;
204+
}
199205
if (PHP_OS_FAMILY === 'Windows' || !function_exists('posix_geteuid') || !class_exists('Phar', false)) {
200206
return null;
201207
}

‎src/Turbo/TurboDiagnoseExtension.php‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
use PHPStan\DependencyInjection\AutowiredService;
77
use PHPStan\Diagnose\DiagnoseExtension;
88
use PHPStan\Php\PhpVersion;
9+
use PHPStan\Process\Restart\OpcacheSettings;
910
use PHPStan\Process\Restart\RestartExtensionRegistry;
1011
use function ini_get;
1112
use function php_uname;
1213
use function phpversion;
1314
use function sprintf;
15+
use function strlen;
16+
use function strpos;
17+
use function substr;
1418
use const PHP_DEBUG;
1519
use const PHP_MAJOR_VERSION;
1620
use const PHP_MINOR_VERSION;
@@ -70,9 +74,37 @@ public function print(Output $output): void
7074
'<info>Turbo trusted types:</info> %s',
7175
$this->describeTrustedTypes(),
7276
));
77+
$output->writeLineFormatted(sprintf(
78+
'<info>OPcache file cache:</info> %s',
79+
$this->describeFileCache(),
80+
));
7381
$output->writeLineFormatted('');
7482
}
7583

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

0 commit comments

Comments
 (0)