|
| 1 | +--TEST-- |
| 2 | +FPM: OPcache Static Cache is separated between pools |
| 3 | +--SKIPIF-- |
| 4 | +<?php include __DIR__ . '/skipif.inc'; ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +require_once __DIR__ . '/tester.inc'; |
| 9 | + |
| 10 | +$cfg = <<<EOT |
| 11 | +[global] |
| 12 | +error_log = {{FILE:LOG}} |
| 13 | +[alpha] |
| 14 | +listen = {{ADDR[alpha]}} |
| 15 | +pm = static |
| 16 | +pm.max_children = 1 |
| 17 | +pm.max_requests = 0 |
| 18 | +catch_workers_output = yes |
| 19 | +[beta] |
| 20 | +listen = {{ADDR[beta]}} |
| 21 | +pm = static |
| 22 | +pm.max_children = 1 |
| 23 | +pm.max_requests = 0 |
| 24 | +catch_workers_output = yes |
| 25 | +EOT; |
| 26 | + |
| 27 | +$code = <<<'PHP' |
| 28 | +<?php |
| 29 | +
|
| 30 | +#[OPcache\PinnedStatic] |
| 31 | +class FpmPoolSeparatePinnedStatic |
| 32 | +{ |
| 33 | + public static int $value = 0; |
| 34 | +} |
| 35 | +
|
| 36 | +class FpmPoolSeparatePinnedProperty |
| 37 | +{ |
| 38 | + #[OPcache\PinnedStatic] |
| 39 | + public static int $value = 0; |
| 40 | +} |
| 41 | +
|
| 42 | +class FpmPoolSeparatePinnedMethod |
| 43 | +{ |
| 44 | + #[OPcache\PinnedStatic] |
| 45 | + public static function value(?int $value = null): int |
| 46 | + { |
| 47 | + static $stored = 0; |
| 48 | +
|
| 49 | + if ($value !== null) { |
| 50 | + $stored = $value; |
| 51 | + } |
| 52 | +
|
| 53 | + return $stored; |
| 54 | + } |
| 55 | +} |
| 56 | +
|
| 57 | +$action = $_GET['action'] ?? 'fetch'; |
| 58 | +$pool = $_GET['pool'] ?? 'unknown'; |
| 59 | +$volatileKey = 'fpm_pool_separate_shared_key'; |
| 60 | +$pinnedKey = 'fpm_pool_separate_pinned_key'; |
| 61 | +
|
| 62 | +if ($action === 'seed') { |
| 63 | + $base = $pool === 'alpha' ? 100 : 200; |
| 64 | +
|
| 65 | + OPcache\volatile_store($volatileKey, $pool . '-volatile'); |
| 66 | + OPcache\pinned_store($pinnedKey, $pool . '-pinned'); |
| 67 | + FpmPoolSeparatePinnedStatic::$value = $base + 1; |
| 68 | + FpmPoolSeparatePinnedProperty::$value = $base + 2; |
| 69 | + FpmPoolSeparatePinnedMethod::value($base + 3); |
| 70 | +} |
| 71 | +
|
| 72 | +printf( |
| 73 | + "%s:%s:%s:%d:%d:%d\n", |
| 74 | + $pool, |
| 75 | + OPcache\volatile_fetch($volatileKey, 'MISS'), |
| 76 | + OPcache\pinned_fetch($pinnedKey, 'MISS'), |
| 77 | + FpmPoolSeparatePinnedStatic::$value, |
| 78 | + FpmPoolSeparatePinnedProperty::$value, |
| 79 | + FpmPoolSeparatePinnedMethod::value() |
| 80 | +); |
| 81 | +PHP; |
| 82 | + |
| 83 | +function expectPoolState(FPM\Tester $tester, string $pool, string $expected): void |
| 84 | +{ |
| 85 | + $response = $tester->request( |
| 86 | + query: 'action=fetch&pool=' . $pool, |
| 87 | + address: '{{ADDR[' . $pool . ']}}', |
| 88 | + ); |
| 89 | + $body = trim((string) $response->getBody()); |
| 90 | + if ($body !== $expected) { |
| 91 | + throw new RuntimeException(sprintf( |
| 92 | + 'Unexpected state for pool %s: expected %s, got %s', |
| 93 | + $pool, |
| 94 | + $expected, |
| 95 | + $body |
| 96 | + )); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +function seedPool(FPM\Tester $tester, string $pool, string $expected): void |
| 101 | +{ |
| 102 | + $response = $tester->request( |
| 103 | + query: 'action=seed&pool=' . $pool, |
| 104 | + address: '{{ADDR[' . $pool . ']}}', |
| 105 | + ); |
| 106 | + $body = trim((string) $response->getBody()); |
| 107 | + if ($body !== $expected) { |
| 108 | + throw new RuntimeException(sprintf( |
| 109 | + 'Unexpected seed state for pool %s: expected %s, got %s', |
| 110 | + $pool, |
| 111 | + $expected, |
| 112 | + $body |
| 113 | + )); |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +$tester = new FPM\Tester($cfg, $code); |
| 118 | +$tester->start(iniEntries: [ |
| 119 | + 'opcache.enable' => '1', |
| 120 | + 'opcache.static_cache.volatile_size_mb' => '32', |
| 121 | + 'opcache.static_cache.pinned_size_mb' => '32', |
| 122 | + 'opcache.file_update_protection' => '0', |
| 123 | +]); |
| 124 | +$tester->expectLogStartNotices(); |
| 125 | + |
| 126 | +seedPool($tester, 'alpha', 'alpha:alpha-volatile:alpha-pinned:101:102:103'); |
| 127 | +expectPoolState($tester, 'alpha', 'alpha:alpha-volatile:alpha-pinned:101:102:103'); |
| 128 | +expectPoolState($tester, 'beta', 'beta:MISS:MISS:0:0:0'); |
| 129 | + |
| 130 | +seedPool($tester, 'beta', 'beta:beta-volatile:beta-pinned:201:202:203'); |
| 131 | +expectPoolState($tester, 'alpha', 'alpha:alpha-volatile:alpha-pinned:101:102:103'); |
| 132 | +expectPoolState($tester, 'beta', 'beta:beta-volatile:beta-pinned:201:202:203'); |
| 133 | + |
| 134 | +$tester->terminate(); |
| 135 | +$tester->expectLogTerminatingNotices(); |
| 136 | +$tester->close(); |
| 137 | + |
| 138 | +echo "Done\n"; |
| 139 | + |
| 140 | +?> |
| 141 | +--EXPECT-- |
| 142 | +Done |
| 143 | +--CLEAN-- |
| 144 | +<?php |
| 145 | +require_once __DIR__ . '/tester.inc'; |
| 146 | +FPM\Tester::clean(); |
| 147 | +?> |
0 commit comments