diff --git a/ext/opcache/tests/gh25555.phpt b/ext/opcache/tests/gh25555.phpt new file mode 100644 index 000000000000..38d06bb2865e --- /dev/null +++ b/ext/opcache/tests/gh25555.phpt @@ -0,0 +1,72 @@ +--TEST-- +GH-25555: Scripts loaded from file_cache into SHM report memory_consumption 0 when stored without SHM +--EXTENSIONS-- +opcache +--FILE-- + 0, $w1 - $w0 === $mem);' + . ' }', + var_export($script, true), + $file_cache_only ? 'true' : 'false', + var_export($script, true), + var_export($script, true), + ); + array_push($cmd, + '-d', 'opcache.enable=1', + '-d', 'opcache.enable_cli=1', + '-d', 'opcache.jit=0', + '-d', 'opcache.file_cache="' . $cache . '"', + '-d', 'opcache.file_cache_only=' . ($file_cache_only ? '1' : '0'), + '-d', 'opcache.file_update_protection=0', + '-r', $code, + ); + $proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['redirect', 1]], $pipes); + echo stream_get_contents($pipes[1]); + proc_close($proc); +} + +run_child($cache, $script, true); +run_child($cache, $script, false); +?> +--CLEAN-- +isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname()); + } + rmdir($cache); +} +?> +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index a8463e4252e6..fc64ba5640d8 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -1987,6 +1987,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl ZCSG(map_ptr_last) = CG(map_ptr_last); zend_accel_pending_ce_cache_commit(); script->dynamic_members.last_used = ZCG(request_time); + script->dynamic_members.memory_consumption = ZEND_ALIGNED_SIZE(script->size); zend_accel_hash_update(&ZCSG(hash), script->script.filename, 0, script);