php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68631 opcache_invalidate always increases wasted memory
Submitted: 2014-12-19 17:04 UTC Modified: 2014-12-20 01:55 UTC
Votes:1
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: Open Package: opcache
PHP Version: 5.5.20 OS: Debian Wheezy
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-12-19 17:04 UTC] iquito at gmx dot net
Description:
------------
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 http://www.panaxis.ch/categories.php - 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: https://www.purplestar.com/categories.php
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 20:01:23 2020 UTC