]> granicus.if.org Git - php/commitdiff
Fixed Issue #140: "opcache.enable_file_override" doesn't respect "opcache.revalidate_...
authorDmitry Stogov <dmitry@zend.com>
Mon, 23 Dec 2013 08:46:30 +0000 (12:46 +0400)
committerDmitry Stogov <dmitry@zend.com>
Mon, 23 Dec 2013 08:46:30 +0000 (12:46 +0400)
NEWS
ext/opcache/ZendAccelerator.c
ext/opcache/ZendAccelerator.h
ext/opcache/tests/issue0140.phpt [new file with mode: 0644]
ext/opcache/zend_accelerator_module.c

diff --git a/NEWS b/NEWS
index 81cd742733a983e98ba5713fe1aea6a60df91c3f..38659e60767c970d48d8c74e44bb5affc037b630 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,8 @@ PHP                                                                        NEWS
 - OPCache:
   . Fixed reavlidate_path=1 behavior to avoid caching of symlinks values.
     (Dmitry)
+  . Fixed Issue #140: "opcache.enable_file_override" doesn't respect
+    "opcache.revalidate_freq". (Dmitry).
 
 - SNMP:
   . Fixed SNMP_ERR_TOOBIG handling for bulk walk operations. (Boris Lytochkin)
index be562359297b45ed5ee104eff8c8167385fc87e8..9662c9912cc02510bdfea77ee540abc7dff4a3a5 100644 (file)
@@ -877,7 +877,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri
        return FAILURE;
 }
 
-static inline int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle TSRMLS_DC)
+int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle TSRMLS_DC)
 {
        if (ZCG(accel_directives).revalidate_freq &&
            (persistent_script->dynamic_members.revalidate >= ZCSG(revalidate_at))) {
index cbc50d2b71e1f30a58d3924256c5f62d5386130f..dbda3b3822c0ab7ca468e28bf40070fdaaab97ce 100644 (file)
@@ -330,6 +330,7 @@ extern char *zps_api_failure_reason;
 void accel_shutdown(TSRMLS_D);
 void zend_accel_schedule_restart(zend_accel_restart_reason reason TSRMLS_DC);
 void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason TSRMLS_DC);
+int  validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle TSRMLS_DC);
 int  zend_accel_invalidate(const char *filename, int filename_len, zend_bool force TSRMLS_DC);
 int  accelerator_shm_read_lock(TSRMLS_D);
 void accelerator_shm_read_unlock(TSRMLS_D);
diff --git a/ext/opcache/tests/issue0140.phpt b/ext/opcache/tests/issue0140.phpt
new file mode 100644 (file)
index 0000000..7c0d6b9
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--\r
+Issue #140: "opcache.enable_file_override" doesn't respect "opcache.revalidate_freq"\r
+--INI--\r
+opcache.enable=1\r
+opcache.enable_cli=1\r
+opcache.revalidate_freq=0\r
+opcache.file_update_protection=0\r
+--SKIPIF--\r
+<?php require_once('skipif.inc'); ?>\r
+<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?>\r
+--FILE--\r
+<?php\r
+define("FILENAME", dirname(__FILE__) . "/issuer0140.inc.php");\r
+file_put_contents(FILENAME, "1\n");\r
+\r
+var_dump(is_readable(FILENAME));\r
+include(FILENAME);\r
+var_dump(filemtime(FILENAME));\r
+\r
+sleep(2);\r
+file_put_contents(FILENAME, "2\n");\r
+\r
+var_dump(is_readable(FILENAME));\r
+include(FILENAME);\r
+var_dump(filemtime(FILENAME));\r
+\r
+sleep(2);\r
+unlink(FILENAME);\r
+\r
+var_dump(is_readable(FILENAME));\r
+var_dump(@include(FILENAME));\r
+var_dump(@filemtime(FILENAME));\r
+?>\r
+--EXPECTF--\r
+bool(true)\r
+1\r
+int(%d)\r
+bool(true)\r
+2\r
+int(%d)\r
+bool(false)\r
+bool(false)\r
+bool(false)\r
index c3df1a68f782faeba27dc83a1f8a9f1fe2f50a78..36d02cc0722637969724da7505cf11e310879c8d 100644 (file)
@@ -313,13 +313,15 @@ static int filename_is_in_cache(char *filename, int filename_len TSRMLS_DC)
        if (IS_ABSOLUTE_PATH(filename, filename_len)) {
                persistent_script = zend_accel_hash_find(&ZCSG(hash), filename, filename_len + 1);
                if (persistent_script) {
-                       return !persistent_script->corrupted;
+                       return !persistent_script->corrupted &&
+                               validate_timestamp_and_record(persistent_script, &handle TSRMLS_CC) == SUCCESS;
                }
        }
 
        if ((key = accel_make_persistent_key_ex(&handle, filename_len, &key_length TSRMLS_CC)) != NULL) {
                persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length + 1);
-               return persistent_script && !persistent_script->corrupted;
+               return persistent_script && !persistent_script->corrupted &&
+                       validate_timestamp_and_record(persistent_script, &handle TSRMLS_CC) == SUCCESS;
        }
 
        return 0;