php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #59818
Patch lazy_stat.patch revision 2013-02-10 12:43 UTC by lazy404 at gmail dot com
revision 2013-02-10 12:41 UTC by lazy404 at gmail dot com

Patch lazy_stat.patch for APC Bug #59818

Patch version 2013-02-10 12:43 UTC

Return to Bug #59818 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: lazy404@gmail.com

Index: php_apc.c
===================================================================
--- php_apc.c	(wersja 834)
+++ php_apc.c	(kopia robocza)
@@ -278,6 +278,7 @@
 STD_PHP_INI_BOOLEAN("apc.lazy_functions", "0", PHP_INI_SYSTEM, OnUpdateBool, lazy_functions, zend_apc_globals, apc_globals)
 STD_PHP_INI_BOOLEAN("apc.lazy_classes", "0", PHP_INI_SYSTEM, OnUpdateBool, lazy_classes, zend_apc_globals, apc_globals)
 STD_PHP_INI_ENTRY("apc.serializer", "default", PHP_INI_SYSTEM, OnUpdateStringUnempty, serializer_name, zend_apc_globals, apc_globals)
+STD_PHP_INI_ENTRY("apc.lazy_stat_interval",            "30",    PHP_INI_SYSTEM, OnUpdateLong,            lazy_stat_interval,              zend_apc_globals, apc_globals)
 PHP_INI_END()
 
 /* }}} */
Index: apc_cache.c
===================================================================
--- apc_cache.c	(wersja 834)
+++ apc_cache.c	(kopia robocza)
@@ -163,6 +163,7 @@
     p->creation_time = t;
     p->access_time = t;
     p->deletion_time = 0;
+    p->next_stat = t+APCG(lazy_stat_interval);
     return p;
 }
 /* }}} */
@@ -665,6 +666,8 @@
 {
     slot_t** slot;
     volatile slot_t* retval = NULL;
+	struct apc_fileinfo_t *fileinfo = NULL;
+	time_t mtime_check;
 
     CACHE_RDLOCK(cache);
     if(key.type == APC_CACHE_KEY_FILE) slot = &cache->slots[hash(key) % cache->num_slots];
@@ -698,6 +701,43 @@
         } else {  /* APC_CACHE_KEY_FPFILE */
             if(((*slot)->key.h == key.h) &&
                 !memcmp((*slot)->key.data.fpfile.fullpath, key.data.fpfile.fullpath, key.data.fpfile.fullpath_len+1)) {
+					if((*slot)->next_stat < t) {
+				    	fileinfo = apc_php_malloc(sizeof(apc_fileinfo_t) TSRMLS_CC);
+
+						if(fileinfo == NULL) {
+							CACHE_RDUNLOCK(cache);
+							return NULL;
+						}
+
+				        if (apc_search_paths(key.data.fpfile.fullpath, "", fileinfo TSRMLS_CC) != 0) {
+				            apc_debug("apc_cache_find_slot(): stat failed %s\n" TSRMLS_CC, key.data.fpfile.fullpath);
+							CACHE_RDUNLOCK(cache);
+							return NULL;
+				        }
+					    if(APCG(stat_ctime)) {
+					        mtime_check= (fileinfo->st_buf.sb.st_ctime > fileinfo->st_buf.sb.st_mtime) ? fileinfo->st_buf.sb.st_ctime : fileinfo->st_buf.sb.st_mtime; 
+					    } else {
+					        mtime_check= fileinfo->st_buf.sb.st_mtime;
+					    }
+						if((*slot)->key.mtime && ( (*slot)->key.mtime != mtime_check)) {
+	                       #if (USE_READ_LOCKS == 0)
+	                       /* this is merely a memory-friendly optimization, if we do have a write-lock
+	                        * might as well move this to the deleted_list right-away. Otherwise an insert
+	                        * of the same key wil do it (or an expunge, *eventually*).
+	                        */
+	                       remove_slot(cache, slot TSRMLS_CC);
+	                       #endif
+	                       CACHE_SAFE_INC(cache, cache->header->num_misses);
+	                       CACHE_RDUNLOCK(cache);
+	                       return NULL;
+						}else {
+                            CACHE_LOCK(cache);
+							(*slot)->next_stat=t+APCG(lazy_stat_interval);
+							(*slot)->key.mtime=mtime_check;
+                            CACHE_UNLOCK(cache);
+                        }
+
+				    }
                 /* TTL Check ? */
                 CACHE_SAFE_INC(cache, (*slot)->num_hits);
                 CACHE_SAFE_INC(cache, (*slot)->value->ref_count);
@@ -979,12 +1019,14 @@
             key->data.fpfile.fullpath = filename;
             key->data.fpfile.fullpath_len = len;
             key->h = string_nhash_8((char *)key->data.fpfile.fullpath, key->data.fpfile.fullpath_len);
-            key->mtime = t;
+            key->mtime = 0;
             key->type = APC_CACHE_KEY_FPFILE;
             goto success;
         } else if(APCG(canonicalize)) {
 
             fileinfo = apc_php_malloc(sizeof(apc_fileinfo_t) TSRMLS_CC);
+			
+            assert(fileinfo != NULL);
 
             if (apc_search_paths(filename, include_path, fileinfo TSRMLS_CC) != 0) {
                 apc_warning("apc failed to locate %s - bailing" TSRMLS_CC, filename);
Index: apc_cache.h
===================================================================
--- apc_cache.h	(wersja 834)
+++ apc_cache.h	(kopia robocza)
@@ -310,6 +310,7 @@
     time_t creation_time;       /* time slot was initialized */
     time_t deletion_time;       /* time slot was removed from cache */
     time_t access_time;         /* time slot was last accessed */
+    time_t next_stat;           /* time of next soft stat*/
 };
 /* }}} */
 
Index: apc_globals.h
===================================================================
--- apc_globals.h	(wersja 834)
+++ apc_globals.h	(kopia robocza)
@@ -71,6 +71,7 @@
     long gc_ttl;            /* parameter to apc_cache_create */
     long ttl;               /* parameter to apc_cache_create */
     long user_ttl;
+    long lazy_stat_interval;/* stat using this interval eaven if stat disabled */
 #if APC_MMAP
     char *mmap_file_mask;   /* mktemp-style file-mask to pass to mmap */
 #endif
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 07:01:30 2024 UTC