]> granicus.if.org Git - php/commitdiff
Fixed bug #65559 (Opcache: cache not cleared if changes occur while running)
authorDmitry Stogov <dmitry@zend.com>
Tue, 26 Nov 2013 07:34:41 +0000 (11:34 +0400)
committerDmitry Stogov <dmitry@zend.com>
Tue, 26 Nov 2013 07:34:41 +0000 (11:34 +0400)
NEWS
ext/opcache/README
ext/opcache/ZendAccelerator.c
ext/opcache/ZendAccelerator.h
ext/opcache/zend_accelerator_module.c
run-tests.php

diff --git a/NEWS b/NEWS
index e8ab470d5ab0dcabcd4c78e82a318847577edf5a..571de403ddf75a15cb3b22f2d32e0b5ce0d9ffb1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP                                                                        NEWS
 
 - OPCache
   . Fixed bug #65915 (Inconsistent results with require return value). (Dmitry)
+  . Fixed bug #65559 (Opcache: cache not cleared if changes occur while
+    running). (Dmitry)
 
 - readline
   . Fixed Bug #65714 (PHP cli forces the tty to cooked mode). (Remi)
index 2e30d92c001e15f5f2af17a1eb4d2f34221399d4..cb6ac342c49b54eade158b2f2e72d87fb7ac434d 100644 (file)
@@ -103,6 +103,12 @@ opcache.revalidate_freq (default "2")
        memory storage allocation. ("1" means validate once per second, but only
        once per request. "0" means always validate)
 
+opcache.file_update_protection (default "2")
+       Prevents caching files that are less than this number of seconds old.
+       It protects from caching of incompletely updated files. In case all file
+       updates on your site are atomic, you may increase performance setting it
+       to "0".
+
 opcache.revalidate_path (default "0")
        Enables or disables file search in include_path optimization
        If the file search is disabled and a cached file is found that uses
index 8eaa0a37788c68ab681e9930dd05a357dbb9a4a2..b2efce9ea20943e222ebe224752325fedaf89b2e 100644 (file)
@@ -1331,7 +1331,9 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
        }
 #endif
 
-       if (ZCG(accel_directives).validate_timestamps || ZCG(accel_directives).max_file_size > 0) {
+       if (ZCG(accel_directives).validate_timestamps ||
+           ZCG(accel_directives).file_update_protection ||
+           ZCG(accel_directives).max_file_size > 0) {
                size_t size = 0;
 
                /* Obtain the file timestamps, *before* actually compiling them,
@@ -1347,6 +1349,13 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
                        return NULL;
                }
 
+               /* check if file is too new (may be it's not written completely yet) */
+               if (ZCG(accel_directives).file_update_protection &&
+                   (ZCG(request_time) - ZCG(accel_directives).file_update_protection < timestamp)) {
+                       *op_array_p = accelerator_orig_compile_file(file_handle, type TSRMLS_CC);
+                       return NULL;
+               }
+
                if (ZCG(accel_directives).max_file_size > 0 && size > (size_t)ZCG(accel_directives).max_file_size) {
                        ZCSG(blacklist_misses)++;
                        *op_array_p = accelerator_orig_compile_file(file_handle, type TSRMLS_CC);
index b9d7ef34704d860c2aa0006f5d76f210d5391004..cbc50d2b71e1f30a58d3924256c5f62d5386130f 100644 (file)
@@ -229,6 +229,7 @@ typedef struct _zend_accel_directives {
        zend_bool      inherited_hack;
        zend_bool      enable_cli;
        unsigned long  revalidate_freq;
+       unsigned long  file_update_protection;
        char          *error_log;
 #ifdef ZEND_WIN32
        char          *mmap_base;
index 0914fb68dd936a21a014b09b58ba800b084d60bd..c3df1a68f782faeba27dc83a1f8a9f1fe2f50a78 100644 (file)
@@ -259,7 +259,8 @@ ZEND_INI_BEGIN()
        STD_PHP_INI_ENTRY("opcache.consistency_checks"    , "0"   , PHP_INI_ALL   , OnUpdateLong,                    accel_directives.consistency_checks,        zend_accel_globals, accel_globals)
        STD_PHP_INI_ENTRY("opcache.force_restart_timeout" , "180" , PHP_INI_SYSTEM, OnUpdateLong,                    accel_directives.force_restart_timeout,     zend_accel_globals, accel_globals)
        STD_PHP_INI_ENTRY("opcache.revalidate_freq"       , "2"   , PHP_INI_ALL   , OnUpdateLong,                    accel_directives.revalidate_freq,           zend_accel_globals, accel_globals)
-       STD_PHP_INI_ENTRY("opcache.preferred_memory_model", ""    , PHP_INI_SYSTEM, OnUpdateStringUnempty,        accel_directives.memory_model,              zend_accel_globals, accel_globals)
+       STD_PHP_INI_ENTRY("opcache.file_update_protection", "2"   , PHP_INI_ALL   , OnUpdateLong,                accel_directives.file_update_protection,    zend_accel_globals, accel_globals)
+       STD_PHP_INI_ENTRY("opcache.preferred_memory_model", ""    , PHP_INI_SYSTEM, OnUpdateStringUnempty,       accel_directives.memory_model,              zend_accel_globals, accel_globals)
        STD_PHP_INI_ENTRY("opcache.blacklist_filename"    , ""    , PHP_INI_SYSTEM, OnUpdateString,                  accel_directives.user_blacklist_filename,   zend_accel_globals, accel_globals)
        STD_PHP_INI_ENTRY("opcache.max_file_size"         , "0"   , PHP_INI_SYSTEM, OnUpdateLong,                    accel_directives.max_file_size,             zend_accel_globals, accel_globals)
 
index a88d37d00014beef6a61561f7f3480648a14fadd..d53c3b6c5ef3b2a2ba5dcbefb2fac1c9ae50957a 100755 (executable)
@@ -241,6 +241,7 @@ $ini_overwrites = array(
                'precision=14',
                'memory_limit=128M',
                'opcache.fast_shutdown=0',
+               'opcache.file_update_protection=0',
        );
 
 function write_information($show_html)