|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68631 opcache_invalidate always increases wasted memory
Submitted: 2014-12-19 17:04 UTC Modified: 2021-07-08 11:25 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: iquito at gmx dot net Assigned:
Status: Verified Package: opcache
PHP Version: 5.5.20 OS: Debian Wheezy
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: iquito at gmx dot net
New email:
PHP Version: OS:


 [2014-12-19 17:04 UTC] iquito at gmx dot net
When calling opcache_invalidate on a script which has not changed since being cached by opcache (and $force is not set), the wasted memory in opcache statistics still increases.

I have a cron job which invalidates certain scripts every minute, as they can be changed at any time and then need to be cached again as soon as possible. With the current implementation of opcache_invalidate scenarios such as these lead to the opcache memory being filled within a short time, triggering a restart of opcache and therefore slowing performance needlessly.

Test script:
Just call opcache_invalidate on a script which has not changed again and again, and check opcache statistics for the increase in wasted memory.

Expected result:
According to the documentation, a script is only invalidated if the modification time of the script is newer than the cached opcodes. Yet if the wasted memory increases, clearly something is happening or being invalidated.

Actual result:
If opcache_invalidate is being called on a script which has not changed, opcache should not have any changes - no invalidation, no increase in wasted memory, no action at all.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-20 01:53 UTC] iquito at gmx dot net
I tested some more and found out, that this bug occures infrequently, and the chances of occurence are higher, if the invalidated script is used/included multiple times (included in a web application, for example) before it is invalidated again, at least that is my theory. If the PHP file is cached once and never used, opcache_invalidate does not increase wasted memory, at least I cannot reproduce it that way.

Yet opcache_invalidate and the use of opcache do not have to be simultaneous. The most "regular" results of an increase in wasted memory were with a website where a PHP file is included in every page with multiple views per minute, and a cron job once a minute where some scripts are invalidated. I also have a feeling that larger scripts increase the chances, but I am not sure.

One PHP file which is included and produces this error quite regularly can be found on - to reproduce I would recommend to load a website which includes that PHP file every 10 seconds, and invalidate the file with opcache_invalidate every minute. With about that setup I reached 350MB of wasted space in 3 hours, quite consistently.

Sorry for the imprecise description - I tried to find some method to make it 100% reproduceable, but did not find a clear way. I hope somebody with inside knowledge of opcache reads this and got enough information to know what causes this, or to know what to look for.
 [2014-12-20 01:55 UTC] iquito at gmx dot net
Sorry, link was wrong, here is the correct link for categories.php:
 [2021-07-08 11:25 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2021-07-08 11:25 UTC]
This is like OPcache is supposed to behave: for performance
reasons, invalidated files are never freed (there is no
defragmentation)[1], and as such reported as wasted memory.

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 10:01:31 2024 UTC