简体   繁体   中英

How to configure php 7.4 opcache to register cache hits?

PHP containers are running with the command php-fpm.
When I exec into one of them and run.

$ php -a
php > print_r(opcache_get_status());

I get the following results

(
    [opcache_enabled] => 1
    [cache_full] =>
    [restart_pending] =>
    [restart_in_progress] =>
    [memory_usage] => Array
        (
            [used_memory] => 20976088
            [free_memory] => 180350504
            [wasted_memory] => 0
            [current_wasted_percentage] => 0
        )

    [interned_strings_usage] => Array
        (
            [buffer_size] => 6291008
            [used_memory] => 499216
            [free_memory] => 5791792
            [number_of_strings] => 10395
        )

    [opcache_statistics] => Array
        (
            [num_cached_scripts] => 0
            [num_cached_keys] => 0
            [max_cached_keys] => 262237
            [hits] => 0
            [start_time] => 1658153738
            [last_restart_time] => 0
            [oom_restarts] => 0
            [hash_restarts] => 0
            [manual_restarts] => 0
            [misses] => 0
            [blacklist_misses] => 0
            [blacklist_miss_ratio] => 0
            [opcache_hit_rate] => 0
        )

    [scripts] => Array
        (
        )

)

Why are the hits 0? Am I looking in the wrong place? Is my configuration wrong?

You are looking at the CLI's status, you need to look at the web process's which is either the CGI or FPM one. There's also a dedicated setting for CLI OP Cache that you could enable, but it probably doesn't make sense which is why it is disabled by default.

So to see this, make a page that you execute with an HTTP request that calls phpinfo()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM