|
| 1 | +--TEST-- |
| 2 | +FPM: OPcache Static Cache status, clear, and reset are pool-local |
| 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 FpmPoolStatusClearResetPinnedStatic |
| 32 | +{ |
| 33 | + public static int $value = 0; |
| 34 | +} |
| 35 | +
|
| 36 | +$action = $_GET['action'] ?? 'status'; |
| 37 | +$pool = $_GET['pool'] ?? 'unknown'; |
| 38 | +$volatileKey = 'fpm_pool_status_clear_reset_volatile_key'; |
| 39 | +$pinnedKey = 'fpm_pool_status_clear_reset_pinned_key'; |
| 40 | +
|
| 41 | +if ($action === 'seed') { |
| 42 | + $base = $pool === 'alpha' ? 100 : 200; |
| 43 | +
|
| 44 | + OPcache\volatile_store($volatileKey, $pool . '-volatile'); |
| 45 | + OPcache\pinned_store($pinnedKey, $pool . '-pinned'); |
| 46 | + FpmPoolStatusClearResetPinnedStatic::$value = $base + 1; |
| 47 | +} elseif ($action === 'volatile_clear') { |
| 48 | + printf("volatile_clear=%d\n", OPcache\volatile_clear()); |
| 49 | +} elseif ($action === 'pinned_clear') { |
| 50 | + printf("pinned_clear=%d\n", OPcache\pinned_clear()); |
| 51 | +} elseif ($action === 'reset') { |
| 52 | + printf("reset=%d\n", opcache_reset()); |
| 53 | +} |
| 54 | +
|
| 55 | +$volatileInfo = OPcache\volatile_cache_info(); |
| 56 | +$pinnedInfo = OPcache\pinned_cache_info(); |
| 57 | +$status = opcache_get_status(); |
| 58 | +$statusVolatile = $status['volatile_cache']; |
| 59 | +$statusPinned = $status['pinned_cache']; |
| 60 | +
|
| 61 | +printf( |
| 62 | + "%s:%s:%s:class=%d:info=%d/%d:status=%d/%d:eq=%d/%d\n", |
| 63 | + $pool, |
| 64 | + OPcache\volatile_fetch($volatileKey, 'MISS'), |
| 65 | + OPcache\pinned_fetch($pinnedKey, 'MISS'), |
| 66 | + FpmPoolStatusClearResetPinnedStatic::$value, |
| 67 | + $volatileInfo->entry_count, |
| 68 | + $pinnedInfo->entry_count, |
| 69 | + $statusVolatile->entry_count, |
| 70 | + $statusPinned->entry_count, |
| 71 | + (int) ($statusVolatile == $volatileInfo), |
| 72 | + (int) ($statusPinned == $pinnedInfo) |
| 73 | +); |
| 74 | +PHP; |
| 75 | + |
| 76 | +function expectPoolAction(FPM\Tester $tester, string $pool, string $action, string $expected): void |
| 77 | +{ |
| 78 | + $response = $tester->request( |
| 79 | + query: 'action=' . $action . '&pool=' . $pool, |
| 80 | + address: '{{ADDR[' . $pool . ']}}', |
| 81 | + ); |
| 82 | + $body = trim((string) $response->getBody()); |
| 83 | + if ($body !== $expected) { |
| 84 | + throw new RuntimeException(sprintf( |
| 85 | + "Unexpected response for pool %s action %s:\nExpected:\n%s\nGot:\n%s", |
| 86 | + $pool, |
| 87 | + $action, |
| 88 | + $expected, |
| 89 | + $body |
| 90 | + )); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +$tester = new FPM\Tester($cfg, $code); |
| 95 | +$tester->start(iniEntries: [ |
| 96 | + 'opcache.enable' => '1', |
| 97 | + 'opcache.static_cache.volatile_size_mb' => '32', |
| 98 | + 'opcache.static_cache.pinned_size_mb' => '32', |
| 99 | + 'opcache.file_update_protection' => '0', |
| 100 | +]); |
| 101 | +$tester->expectLogStartNotices(); |
| 102 | + |
| 103 | +$alphaSeeded = 'alpha:alpha-volatile:alpha-pinned:class=101:info=1/2:status=1/2:eq=1/1'; |
| 104 | +$betaSeeded = 'beta:beta-volatile:beta-pinned:class=201:info=1/2:status=1/2:eq=1/1'; |
| 105 | +$alphaVolatileCleared = "volatile_clear=1\nalpha:MISS:alpha-pinned:class=101:info=0/2:status=0/2:eq=1/1"; |
| 106 | +$alphaPinnedCleared = "pinned_clear=1\nalpha:alpha-volatile:MISS:class=0:info=1/0:status=1/0:eq=1/1"; |
| 107 | +$alphaReset = "reset=1\nalpha:MISS:MISS:class=0:info=0/0:status=0/0:eq=1/1"; |
| 108 | + |
| 109 | +expectPoolAction($tester, 'alpha', 'seed', $alphaSeeded); |
| 110 | +expectPoolAction($tester, 'beta', 'seed', $betaSeeded); |
| 111 | +expectPoolAction($tester, 'alpha', 'status', $alphaSeeded); |
| 112 | +expectPoolAction($tester, 'beta', 'status', $betaSeeded); |
| 113 | + |
| 114 | +expectPoolAction($tester, 'alpha', 'volatile_clear', $alphaVolatileCleared); |
| 115 | +expectPoolAction($tester, 'beta', 'status', $betaSeeded); |
| 116 | + |
| 117 | +expectPoolAction($tester, 'alpha', 'seed', $alphaSeeded); |
| 118 | +expectPoolAction($tester, 'alpha', 'pinned_clear', $alphaPinnedCleared); |
| 119 | +expectPoolAction($tester, 'beta', 'status', $betaSeeded); |
| 120 | + |
| 121 | +expectPoolAction($tester, 'alpha', 'seed', $alphaSeeded); |
| 122 | +expectPoolAction($tester, 'alpha', 'reset', $alphaReset); |
| 123 | +expectPoolAction($tester, 'beta', 'status', $betaSeeded); |
| 124 | +expectPoolAction($tester, 'alpha', 'status', 'alpha:MISS:MISS:class=0:info=0/0:status=0/0:eq=1/1'); |
| 125 | + |
| 126 | +$tester->terminate(); |
| 127 | +$tester->expectLogTerminatingNotices(); |
| 128 | +$tester->close(); |
| 129 | + |
| 130 | +echo "Done\n"; |
| 131 | + |
| 132 | +?> |
| 133 | +--EXPECT-- |
| 134 | +Done |
| 135 | +--CLEAN-- |
| 136 | +<?php |
| 137 | +require_once __DIR__ . '/tester.inc'; |
| 138 | +FPM\Tester::clean(); |
| 139 | +?> |
0 commit comments