From: anders dot henke at 1und1 dot de
Operating system: Linux
PHP version: 7.3.1
Package: opcache
Bug Type: Bug
Bug description:opcache_reset() does not reset an opcache.file_cache-based cache
Description:
------------
From PHP 7.0 on, PHP's opcache includes a file-cache as an optional
overflow mechanism and optionally as the only kind of opcache storage
(opcache.file_cache_only=1). The later is interesting in CGI-mode, where
shared memory does not survive a single PHP run.
PHP's opcache does provide a function opcache_reset() to "reset the
entire opcode cache. After calling opcache_reset(), all scripts will be
reloaded and reparsed the next time they are hit.".
This function may be called explicitely (e.g. during software
deployment) to clear any caches and remove accumulated stale cache
objects who are no longer being accessed. Whenever a file-based opcache
storage is being added to Opcache, opcache_reset() does only reset a
shared memory-based opcache, but does not reset any file-based opcache
storage.
In a performance-optimized setup, a user may use shared-memory-based
opcache with file-based opcache storage as a fallback, disable automatic
revalidation and manually perform opcache_reset() during the deployment
process. In such a situation, opcache_reset() returns true and restarts
the shared memory-based storage, but does not remove any objects from
the file-based opcache storage. This possibly might result in running
code from outdated cache objects.
Test script:
---------------
php.ini:
---cut
zend_extension=opcache.so;
opcache.enable=1;
opcache.revalidate_freq=180;
opcache.validate_timestamps=2;
opcache.file_cache=/var/tmp/opcache;
opcache.file_cache_only=1;
---cut
clear.php:
---cut
<pre>
<?php
echo "**Before Clear Opcache:\n";
system('ls -lRt ' . ini_get('opcache.file_cache'));
echo "\n\n**Clear Opcache: ";
var_dump(opcache_reset());
echo "\n";
echo "**After Clear Opcache:\n";
system('ls -lRt ' . ini_get('opcache.file_cache'));
?>
</pre>
---cut
Expected result:
----------------
http://php.net/manual/en/function.opcache-reset.php
states "This
function resets the entire opcode cache. After calling opcache_reset(),
all scripts will be reloaded and reparsed the next time they are hit.
According to my reading, "reset the entire opcache" does also include
the file-based opcache.
In my test script above, the actual content "before" and "after"
opcache_reset() stays the same.
Actual result:
--------------
opcache_reset() does not affect a file-based opcache at all and only
restarts the shared-memory-based opcache.
In a file_cache_only-configuration, opcache_reset() does not reset the
file-based opcache, but returns "false", which should only happen when
opcache is disabled.
According to phpinfo(), opcache is enabled and running.
In a overflow/fallback configuration, opcache_reset() does return true,
but will only restart the shared memory storage and not reset any
file-based opcache storage. Depending on the overall configuration, this
might result in running cached but outdated code. Such an issue has also
been reported in bug #75670.
--
Edit bug report at https://bugs.php.net/bug.php?id=77478&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77478&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77478&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77478&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77478&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77478&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77478&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77478&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77478&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77478&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77478&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77478&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77478&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77478&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77478&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77478&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77478&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77478&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77478&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77478&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77478&r=mysqlcfg