]> granicus.if.org Git - php/commitdiff
Fixed bug #75720 (File cache not populated after SHM runs full)
authorDmitry Stogov <dmitry@zend.com>
Thu, 28 Dec 2017 11:08:12 +0000 (14:08 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 28 Dec 2017 11:08:12 +0000 (14:08 +0300)
NEWS
ext/opcache/ZendAccelerator.c

diff --git a/NEWS b/NEWS
index 9d44be5ac3ac849e13b58e5080fed777719c263d..5a69457c80b0c8298e6a7d68a4bf45f1a937db0e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ PHP                                                                        NEWS
   . Fixed bug #75679 (Path 260 character problem). (Anatol)
 
 - Opcache:
+  . Fixed bug #75720 (File cache not populated after SHM runs full). (Dmitry)
   . Fixed bug #75579 (Interned strings buffer overflow may cause crash).
     (Dmitry)
 
index 1c5b800c6b25a81850d110e434d7e748e3b6d18b..b4033fb05302c0cd79a54993b5664417945cf38f 100644 (file)
@@ -1214,19 +1214,10 @@ static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_ha
 }
 
 #ifdef HAVE_OPCACHE_FILE_CACHE
-static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script *new_persistent_script, int *from_shared_memory)
+static zend_persistent_script *store_script_in_file_cache(zend_persistent_script *new_persistent_script)
 {
        uint memory_used;
 
-       /* Check if script may be stored in shared memory */
-       if (!zend_accel_script_persistable(new_persistent_script)) {
-               return new_persistent_script;
-       }
-
-       if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) {
-               return new_persistent_script;
-       }
-
        zend_shared_alloc_init_xlat_table();
 
        /* Calculate the required memory size */
@@ -1266,9 +1257,23 @@ static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script
 
        zend_file_cache_script_store(new_persistent_script, 0);
 
-       *from_shared_memory = 1;
        return new_persistent_script;
 }
+
+static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script *new_persistent_script, int *from_shared_memory)
+{
+       /* Check if script may be stored in shared memory */
+       if (!zend_accel_script_persistable(new_persistent_script)) {
+               return new_persistent_script;
+       }
+
+       if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) {
+               return new_persistent_script;
+       }
+
+       *from_shared_memory = 1;
+       return store_script_in_file_cache(new_persistent_script);
+}
 #endif
 
 static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, char *key, unsigned int key_length, int *from_shared_memory)
@@ -1288,14 +1293,6 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
        /* exclusive lock */
        zend_shared_alloc_lock();
 
-       if (zend_accel_hash_is_full(&ZCSG(hash))) {
-               zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
-               ZSMMG(memory_exhausted) = 1;
-               zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH);
-               zend_shared_alloc_unlock();
-               return new_persistent_script;
-       }
-
        /* Check if we still need to put the file into the cache (may be it was
         * already stored by another process. This final check is done under
         * exclusive lock) */
@@ -1314,6 +1311,19 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
                }
        }
 
+       if (zend_accel_hash_is_full(&ZCSG(hash))) {
+               zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
+               ZSMMG(memory_exhausted) = 1;
+               zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH);
+               zend_shared_alloc_unlock();
+#ifdef HAVE_OPCACHE_FILE_CACHE
+               if (ZCG(accel_directives).file_cache) {
+                       new_persistent_script = store_script_in_file_cache(new_persistent_script);
+                       *from_shared_memory = 1;
+               }
+#endif
+               return new_persistent_script;
+       }
 
        zend_shared_alloc_init_xlat_table();
 
@@ -1332,6 +1342,12 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
                zend_shared_alloc_destroy_xlat_table();
                zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
                zend_shared_alloc_unlock();
+#ifdef HAVE_OPCACHE_FILE_CACHE
+               if (ZCG(accel_directives).file_cache) {
+                       new_persistent_script = store_script_in_file_cache(new_persistent_script);
+                       *from_shared_memory = 1;
+               }
+#endif
                return new_persistent_script;
        }
 
@@ -1867,6 +1883,11 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
                if (ZSMMG(memory_exhausted) || ZCSG(restart_pending)) {
                        SHM_PROTECT();
                        HANDLE_UNBLOCK_INTERRUPTIONS();
+#ifdef HAVE_OPCACHE_FILE_CACHE
+                       if (ZCG(accel_directives).file_cache) {
+                               return file_cache_compile_file(file_handle, type);
+                       }
+#endif
                        return accelerator_orig_compile_file(file_handle, type);
                }