cache not cleared if changes occur while running
| Bug #65559 | Opcache: cache not cleared if changes occur while running | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2013-08-26 12:41 UTC | Modified: | 2013-11-25 10:41 UTC |
|
||||||||||
| From: | zoeslam at gmail dot com | Assigned: | dmitry (profile) | |||||||||||
| Status: | Closed | Package: | opcache | |||||||||||
| PHP Version: | 5.5.3 | OS: | Ubuntu | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[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)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2013-10-23 14:09 UTC] zoeslam at gmail dot com
[2013-11-04 14:54 UTC] zoeslam at gmail dot com
[2013-11-05 06:50 UTC] dmitry@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
[2013-11-19 13:46 UTC] Terry at ellisons dot org dot uk
[2013-11-19 13:52 UTC] zoeslam at gmail dot com
[2013-11-19 14:04 UTC] arjen at react dot com
[2013-11-21 22:01 UTC] nanobreaker at mail dot bg
[2013-11-25 10:41 UTC] dmitry@php.net
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.[2013-11-25 10:54 UTC] zoeslam at gmail dot com
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.[2013-11-26 07:37 UTC] dmitry@php.net
-Status: Assigned +Status: Closed