amnuts / opcache-gui

A clean, effective and responsive interface for Zend OPcache
1.21k stars 197 forks source link

Setting `opcache.validate_timestamps=0` causes all files to display "has been invalidated" #92

Open pereorga opened 1 year ago

pereorga commented 1 year ago

I have the following opcache settings:

opcache.enable=1
opcache.validate_timestamps=0
opcache.enable_file_override=1
opcache.save_comments=0
opcache.file_update_protection=0

This is consistent with the stats I'm seeing:

number of cached files: 20
number of hits: 1,199,633
number of misses: 20
number of cached keys: 29

However, in the "Cached" tab, I see "has been invalidated" on every entry:

/srv/app/src/common.php
hits: 29,977, memory: 62.95KB, last used: Thu, 15 Sep 2022 11:28:46 +0000 - has been invalidated

Is that correct? My understanding is that all my files should never invalidate.

Also, could anyone confirm that the "last used" date is the date of the last hit? the screenshot included in the readme confuses me a little bit, as it has a date from 1970:

https://camo.githubusercontent.com/ceba44e11a4e8c494ccd65bb72669579e527ca115b1941153a052781c2cdc129/687474703a2f2f616d6e7574732e636f6d2f696d616765732f6f7063616368652f73637265656e73686f742f6361636865642d76332e706e67

M-Falken commented 1 year ago

Hi perhaps this is part of it mine is set on 2 (default) _opcache.file_updateprotection string Prevents caching files that are less than this number of seconds old. It protects from caching of incompletely updated files. In case all file updates on your site are atomic, you may increase performance by setting it to "0".

stlrnz commented 1 year ago

I can confirm, that "has been invalidated" is shown for every entry. However, the hit counter is counting up and my hit rate is 99%. So I asume this is a bug.

opcache.file_update_protection is set to 2 in my environment.

pereorga commented 1 year ago

Thanks @M-Falken and @stlrnz

perhaps this is part of it mine is set on 2 (default) opcache.file_update_protection string Prevents caching files that are less than this number of seconds old.

No, my understanding is that setting this to 0 disables the feature, and thereby all files are cached (which is better performance-wise, as timestamps do not need to be checked)

M-Falken commented 1 year ago

@pereorga I think you confuse with _opcache.validatetimestamps

pereorga commented 1 year ago

@M-Falken no, these are different options indeed, and I am not confusing them:

opcache.file_update_protection string
Prevents caching files that are less than this number of seconds old. It protects from caching of incompletely updated files. In case all file updates on your site are atomic, you may increase performance by setting it to "0".
opcache.validate_timestamps bool
If enabled, OPcache will check for updated scripts every [opcache.revalidate_freq](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq) seconds. When this directive is disabled, you must reset OPcache manually via [opcache_reset()](https://www.php.net/manual/en/function.opcache-reset.php), [opcache_invalidate()](https://www.php.net/manual/en/function.opcache-invalidate.php) or by restarting the Web server for changes to the filesystem to take effect.

So file_update_protection is a feature to avoid issues when caching files that are being edited. But I do not need this feature because I only change files when my docker container is rebuilt. Disabling both options prevents checking timestamps for all files, in all cases:

opcache.validate_timestamps=0
opcache.file_update_protection=0

In the first one, OPcache won't validate timestamps during run-time. In the second one, OPcache won't validate them during compile-time.

lucasnetau commented 11 months ago

If opcache.validate_timestamps=0 there is no timestamp property returned by opcache_get_status(true); The codepath that displays '- has been invalidated' shows when there is no timestamp value which in this case is incorrect since the file hasn't been invalidated

With opcache.validate_timestamps=1

...
[scripts] => Array
        (
            [/tmp/php.php] => Array
                (
                    [full_path] => /tmp/php.php
                    [hits] => 0
                    [memory_consumption] => 656
                    [last_used] => Wed Jul 26 01:44:24 2023
                    [last_used_timestamp] => 1690335864
                    [timestamp] => 1690335668
                )

        )
...

With opcache.validate_timestamps=0

...
    [scripts] => Array
        (
            [/tmp/php.php] => Array
                (
                    [full_path] => /tmp/php.php
                    [hits] => 0
                    [memory_consumption] => 656
                    [last_used] => Wed Jul 26 01:41:14 2023
                    [last_used_timestamp] => 1690335674
                )

        )
...