|
| 1 | +--TEST-- |
| 2 | +opcache file cache must not reuse frameless function indices across extension sets |
| 3 | +--EXTENSIONS-- |
| 4 | +opcache |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +$dl_test = PHP_OS_FAMILY === 'Windows' ? 'php_dl_test.dll' : 'dl_test.so'; |
| 8 | +if (!file_exists(ini_get('extension_dir') . DIRECTORY_SEPARATOR . $dl_test)) { |
| 9 | + die('skip dl_test extension is not built'); |
| 10 | +} |
| 11 | +?> |
| 12 | +--FILE-- |
| 13 | +<?php |
| 14 | +$cache = __DIR__ . DIRECTORY_SEPARATOR . 'file_cache_frameless_handler'; |
| 15 | +$script = $cache . DIRECTORY_SEPARATOR . 'call.php'; |
| 16 | +mkdir($cache); |
| 17 | +file_put_contents($script, <<<'PHP' |
| 18 | +<?php |
| 19 | +if (isset($argv[1])) { |
| 20 | + dl('dl_test'); |
| 21 | +} |
| 22 | +try { |
| 23 | + var_dump(dl_test_frameless(7)); |
| 24 | +} catch (Error $e) { |
| 25 | + echo $e::class, ": ", $e->getMessage(), "\n"; |
| 26 | +} |
| 27 | +PHP); |
| 28 | + |
| 29 | +function run(string $cache, array $args): void { |
| 30 | + $ext = ini_get('extension_dir'); |
| 31 | + $opcache = PHP_OS_FAMILY === 'Windows' ? 'php_opcache.dll' : 'opcache.so'; |
| 32 | + $cmd = [PHP_BINARY, '-n', '-d', 'extension_dir="' . $ext . '"']; |
| 33 | + if (file_exists($ext . DIRECTORY_SEPARATOR . $opcache)) { |
| 34 | + array_push($cmd, '-d', 'zend_extension=opcache'); |
| 35 | + } |
| 36 | + array_push($cmd, |
| 37 | + '-d', 'opcache.enable_cli=1', |
| 38 | + '-d', 'opcache.file_cache="' . $cache . '"', |
| 39 | + '-d', 'opcache.file_cache_only=1', |
| 40 | + '-d', 'opcache.file_update_protection=0', |
| 41 | + ...$args, |
| 42 | + ); |
| 43 | + $proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); |
| 44 | + echo stream_get_contents($pipes[1]); |
| 45 | + stream_get_contents($pipes[2]); |
| 46 | + proc_close($proc); |
| 47 | +} |
| 48 | + |
| 49 | +function system_ids(string $cache): int { |
| 50 | + $pattern = PHP_OS_FAMILY === 'Windows' ? '/*/*' : '/*'; |
| 51 | + return count(glob($cache . $pattern, GLOB_ONLYDIR)); |
| 52 | +} |
| 53 | + |
| 54 | +run($cache, ['-d', 'extension=dl_test', $script]); |
| 55 | +var_dump(system_ids($cache)); |
| 56 | +run($cache, [$script, 'dl']); |
| 57 | +var_dump(system_ids($cache)); |
| 58 | +run($cache, [$script]); |
| 59 | +var_dump(system_ids($cache)); |
| 60 | +?> |
| 61 | +--CLEAN-- |
| 62 | +<?php |
| 63 | +$cache = __DIR__ . DIRECTORY_SEPARATOR . 'file_cache_frameless_handler'; |
| 64 | +if (is_dir($cache)) { |
| 65 | + $it = new RecursiveIteratorIterator( |
| 66 | + new RecursiveDirectoryIterator($cache, FilesystemIterator::SKIP_DOTS), |
| 67 | + RecursiveIteratorIterator::CHILD_FIRST |
| 68 | + ); |
| 69 | + foreach ($it as $file) { |
| 70 | + $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname()); |
| 71 | + } |
| 72 | + rmdir($cache); |
| 73 | +} |
| 74 | +?> |
| 75 | +--EXPECT-- |
| 76 | +int(7) |
| 77 | +int(1) |
| 78 | +int(7) |
| 79 | +int(2) |
| 80 | +Error: Call to undefined function dl_test_frameless() |
| 81 | +int(2) |
0 commit comments