Skip to content

Commit 27d0bfd

Browse files
Sander Mullerclaude
andcommitted
Probe OPcache from inside a PHPStan run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ba9270d commit 27d0bfd

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

‎.github/workflows/probe.yml‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ jobs:
2323
coverage: none
2424
tools: composer
2525
- run: (cd bench/project && composer install -q --no-interaction)
26-
- name: phar as Composer installed it
27-
run: php -d opcache.enable_cli=1 -d opcache.validate_timestamps=1 -d opcache.file_update_protection=0 -d opcache.max_file_size=0 probe/mtime.php bench/project/vendor/phpstan/phpstan/phpstan.phar
28-
- name: default file_update_protection
29-
run: php -d opcache.enable_cli=1 -d opcache.validate_timestamps=1 probe/mtime.php bench/project/vendor/phpstan/phpstan/phpstan.phar
30-
- name: phar file dates
31-
run: ls -la --time-style=full-iso bench/project/vendor/phpstan/phpstan/ 2>/dev/null || ls -laT bench/project/vendor/phpstan/phpstan/
26+
- name: Inside PHPStan, stock / timestamps off / timestamps on
27+
run: |
28+
PKG=bench/project/vendor/phpstan/phpstan
29+
mkdir -p "$RUNNER_TEMP/fc0" "$RUNNER_TEMP/fcv"
30+
for arm in stock fc0 fcv; do cp -R $PKG "$RUNNER_TEMP/arm-$arm"; done
31+
php -d phar.readonly=0 bench/make-arm.php "$RUNNER_TEMP/arm-fc0/phpstan.phar" sha512 "$RUNNER_TEMP/fc0"
32+
php -d phar.readonly=0 bench/make-arm.php "$RUNNER_TEMP/arm-fcv/phpstan.phar" sha512 "$RUNNER_TEMP/fcv" vts
33+
cd probe/proj
34+
for arm in stock fc0 fcv; do for run in 1 2; do
35+
echo "== $arm run $run"
36+
php "$RUNNER_TEMP/arm-$arm/phpstan.phar" analyse -c phpstan.neon --debug --no-progress 2>&1 | grep PROBE || true
37+
done; done
38+
find "$RUNNER_TEMP/fcv" -name '*.bin' | wc -l

‎probe/proj/bootstrap.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
$f = (new ReflectionClass(\PHPStan\Analyser\MutatingScope::class))->getFileName();
3+
$st = opcache_get_status(true);
4+
$phar = 0; $plain = 0;
5+
foreach ($st['scripts'] ?? [] as $path => $_) { str_starts_with($path, 'phar://') ? $phar++ : $plain++; }
6+
fwrite(STDERR, 'PROBE ' . json_encode([
7+
'os' => PHP_OS, 'file' => $f,
8+
'stat_mtime' => @stat($f)['mtime'] ?? null,
9+
'filemtime' => @filemtime($f),
10+
'is_cached' => opcache_is_script_cached($f),
11+
'shm_scripts_phar' => $phar, 'shm_scripts_plain' => $plain,
12+
'vts' => ini_get('opcache.validate_timestamps'), 'fc' => ini_get('opcache.file_cache'),
13+
'turbo' => extension_loaded('phpstan_turbo'),
14+
'wrappers' => stream_get_wrappers(),
15+
], JSON_UNESCAPED_SLASHES) . "\n");

‎probe/proj/phpstan.neon‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: max
3+
paths: [src]
4+
bootstrapFiles: [bootstrap.php]

‎probe/proj/src/Foo.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php declare(strict_types = 1);
2+
namespace App;
3+
final class Foo { public function bar(int $a): int { return $a * 2; } }

0 commit comments

Comments
 (0)