Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pereorga opened this issue Sep 15, 2022 · 6 comments

Comments

@pereorga
Copy link

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
Copy link
Contributor

Hi
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. 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
Copy link

stlrnz commented Sep 30, 2022

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
Copy link
Author

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
Copy link
Contributor

@pereorga
I think you confuse with opcache.validate_timestamps

@pereorga
Copy link
Author

pereorga commented Oct 18, 2022

@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
Copy link

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
                )

        )
...

@pereorga pereorga changed the title Seeing "has been invalidated" on every file Setting opcache.validate_timestamps=0 causes all files to display "has been invalidated" Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants