|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-08-26 12:41 UTC] zoeslam at gmail dot com
Description: ------------ The new Zend OPcache doesn't clear the cache if a file is changed on the fly. Instead the test script works well with opcache turned off (opcache.enable=0). Test script: --------------- <?php $file = __DIR__.'/file.txt'; file_put_contents($file, '<?php return 1;'); $var = include $file; file_put_contents($file, '<?php return 2;'); $var = include $file; var_dump($var); Expected result: ---------------- int(2) Actual result: -------------- int(1) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 06:00:01 2025 UTC |
APC made a hack to prevent caching of just updated files. This makes the test passed. With opcache.revalidate_freq=0 OPCache checks file modification time on each include(), but the test script most probably makes two writes in a single second. So file modification times are the same. If you insert sleep(1) between inclue()s, it works as expected. To workaround the problem you may add the file into blacklist or use opcache_invalidate(): if (function_exists("opcache_invalidate")) opcache_invalidate($file, true); We may also hack OPCache similar to APC, but I'm not sure it's the right way.Hi dmitry, almost all http requests last less than 1 second, and it's common to write this cache algorithm: $var = include $cachefile; if (must_renew($var)) { file_put_contents($cachefile, renew($var)); $var = include $cachefile; } use($var); So I think APC did a workaround just because of that common usage. Your workaround works, but it' pretty bad to couple a general algorithm to teh cache subsystem.