php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #59951
Patch apc-stat-patch revision 2011-10-22 06:50 UTC by noda dot yoshikazu at gmail dot com

Patch apc-stat-patch for APC Bug #59951

Patch version 2011-10-22 06:50 UTC

Return to Bug #59951 | Download this patch
Patch Revisions:

Developer: noda.yoshikazu@gmail.com

diff -crb APC-3.1.9/apc.c APC-3.1.9-M/apc.c
*** APC-3.1.9/apc.c	2011-05-15 07:14:56.000000000 +0900
--- APC-3.1.9-M/apc.c	2011-10-22 10:17:35.020459641 +0900
***************
*** 294,299 ****
--- 294,395 ----
  #endif
  /* }}} */
  
+ #define LESSSTAT 1
+ 
+ #ifdef LESSSTAT
+ 
+ /* {{{ binary search simple array of char* */
+ /* Returns 1 on found and 0 otherwise. */
+ static int binsearch (char** array, int used, const char* target)  
+ {
+ 	int low, high, mid, result;
+ 
+ 	if (0 < used) {
+ 		low = 0;
+ 		high = used - 1;
+ 		while (low <= high) {
+ 			mid = (low + high) / 2;
+ 			result = strcmp (array[mid], target);
+ 			if (result > 0)
+ 				high = mid - 1;
+ 			else if (result < 0)
+ 				low = mid + 1;
+ 			else
+ 				return 1; // found!
+ 		}
+ 	}
+ 	return 0; // not found..
+ }
+ 
+ #define STAT_SUCCESS_LIST_SZINC  (1024*8)
+ static char** stat_success_list=NULL;
+ static int    stat_success_list_max = STAT_SUCCESS_LIST_SZINC;
+ static int    stat_success_list_used = 0;
+ 
+ /* use insert_stat_success_list instead of add_stat_success_list */
+ static int insert_stat_success_list (const char* path)
+ {
+ 	int i = 0, r;
+ 
+ 	if (!stat_success_list) {
+ 		// initial setup
+ 		stat_success_list = apc_emalloc (stat_success_list_max * sizeof(char*) TSRMLS_CC); // initial malloc
+ 		stat_success_list_max=STAT_SUCCESS_LIST_SZINC;
+ 		stat_success_list_used=0;
+ 	}
+ 	if (stat_success_list_used == stat_success_list_max) {
+ 		// Need to increase the path array size
+ 		stat_success_list_max += STAT_SUCCESS_LIST_SZINC;
+ 		stat_success_list = apc_erealloc (stat_success_list, (stat_success_list_max * sizeof(char*)) TSRMLS_CC);
+ 	}
+ 	i = 0;
+ 	// Look for the slot
+ 	while (i < stat_success_list_used) {
+ 		r = strcmp (stat_success_list[i], path);
+ 		if (r == 0)
+ 			return; // have the same entry already.
+ 		else if (r > 0)
+ 			break;   // list[i] > path
+ 		i++;
+ 	}
+ 	if (i == stat_success_list_used) {
+ 		// Only append to the end
+ 		stat_success_list[stat_success_list_used] = apc_estrdup (path TSRMLS_CC);
+ 		stat_success_list_used++;
+ 	}
+ 	else {
+ 		// move some content to create a room to insert arg path.
+ 		void *source, *dest;
+ 		int size;
+ 		source = &stat_success_list[i];
+ 		dest = &stat_success_list[i+1];
+ 		size = (stat_success_list_used - i) * sizeof (char*);
+ 		memmove (dest, source, size);
+ 		stat_success_list[i] = apc_estrdup (path TSRMLS_CC);
+ 		stat_success_list_used++;
+ 	}
+ 	return 0; // okay
+ }
+ 
+ /* lookup stat_success_list to see path exists */
+ static int query_stat_success_list (const char* path) 
+ {
+ 	return binsearch (stat_success_list, stat_success_list_used, path);
+ }
+ 
+ /* delete stat_success_list */
+ void delete_stat_success_list ()
+ {
+ 	int i;
+ 	for (i = 0; i < stat_success_list_used; i++)
+ 		apc_efree (stat_success_list[i] TSRMLS_CC);
+ 	apc_efree (stat_success_list TSRMLS_CC);
+ 	stat_success_list_used = 0;
+ 	stat_success_list = NULL;
+ }
+ #endif
+ 
+ 
  int apc_search_paths(const char* filename, const char* path, apc_fileinfo_t* fileinfo TSRMLS_DC)
  {
      char** paths = NULL;
***************
*** 306,312 ****
  
      assert(filename && fileinfo);
  
- 
      wrapper = php_stream_locate_url_wrapper(filename, &path_for_open, 0 TSRMLS_CC);
  
      if(!wrapper || !wrapper->wops || !wrapper->wops->url_stat) {
--- 402,407 ----
***************
*** 335,341 ****
          /* for each directory in paths, look for filename inside */
          for (i = 0; paths[i]; i++) {
              snprintf(fileinfo->path_buf, sizeof(fileinfo->path_buf), "%s%c%s", paths[i], DEFAULT_SLASH, path_for_open);
!             if (APC_URL_STAT(wrapper, fileinfo->path_buf, &fileinfo->st_buf) == 0) {
                  fileinfo->fullpath = (char*) fileinfo->path_buf;
                  found = 1;
                  break;
--- 430,454 ----
          /* for each directory in paths, look for filename inside */
          for (i = 0; paths[i]; i++) {
              snprintf(fileinfo->path_buf, sizeof(fileinfo->path_buf), "%s%c%s", paths[i], DEFAULT_SLASH, path_for_open);
! #ifdef LESSSTAT
!             /**********************************************************
!              * check if fileinfo->path_buf entry is in "stat_success_list".
!              * if yes, then set found=1 and break.
!              **********************************************************/
!             if (query_stat_success_list (fileinfo->path_buf)) {
!                 fileinfo->fullpath = (char*) fileinfo->path_buf;
! 	        fileinfo->st_buf.sb.st_size = 0;
!                 found = 1;
!                 break;
!             }
! #endif
!             if (APC_URL_STAT(wrapper, fileinfo->path_buf, &fileinfo->st_buf) == 0) { // calls php_plain_files_url_stater()
! #ifdef LESSSTAT
!                 /**********************************************************
!                  * Success! Save fileinfo->path_buf somewhere.-> let's say it is "stat_success_list"
!                  **********************************************************/
!                 insert_stat_success_list (fileinfo->path_buf);
! #endif
  	        fileinfo->fullpath = (char*) fileinfo->path_buf;
                  found = 1;
                  break;
diff -crb APC-3.1.9/apc_main.c APC-3.1.9-M/apc_main.c
*** APC-3.1.9/apc_main.c	2011-05-15 07:14:56.000000000 +0900
--- APC-3.1.9-M/apc_main.c	2011-10-22 10:17:41.792478154 +0900
***************
*** 49,54 ****
--- 49,55 ----
  
  #define APC_MAX_SERIALIZERS 16
  
+ 
  /* {{{ module variables */
  
  /* pointer to the original Zend engine compile_file function */
***************
*** 492,497 ****
--- 493,499 ----
      int bailout=0;
      const char* filename = NULL;
  
+     apc_debug("0. h->opened_path=[%s]  h->filename=[%s]\n" TSRMLS_CC, h->opened_path?h->opened_path:"null",h->filename);
      if (!APCG(enabled) || apc_cache_busy(apc_cache)) {
          return old_compile_file(h, type TSRMLS_CC);
      }
***************
*** 513,520 ****
          return old_compile_file(h, type TSRMLS_CC);
      }
      APCG(current_cache) = apc_cache;
- 
- 
      t = apc_time();
  
      apc_debug("1. h->opened_path=[%s]  h->filename=[%s]\n" TSRMLS_CC, h->opened_path?h->opened_path:"null",h->filename);
--- 515,520 ----
***************
*** 588,595 ****
                  return old_compile_file(h, type TSRMLS_CC);
              }
          }
!         if (APCG(max_file_size) < fileinfo.st_buf.sb.st_size) { 
!             apc_debug("File is too big %s (%ld) - bailing\n" TSRMLS_CC, h->filename, fileinfo.st_buf.sb.st_size);
              return old_compile_file(h, type TSRMLS_CC);
          }
          key.mtime = fileinfo.st_buf.sb.st_mtime;
--- 588,595 ----
                  return old_compile_file(h, type TSRMLS_CC);
              }
          }
!         if ((long)APCG(max_file_size) < (long)fileinfo.st_buf.sb.st_size) { 
!             apc_debug("File is too big %s max=%ld (%ld) - bailing\n" TSRMLS_CC, h->filename, APCG(max_file_size), fileinfo.st_buf.sb.st_size);
              return old_compile_file(h, type TSRMLS_CC);
          }
          key.mtime = fileinfo.st_buf.sb.st_mtime;
***************
*** 629,635 ****
      HANDLE_UNBLOCK_INTERRUPTIONS();
  
      if (bailout) zend_bailout();
- 
      return op_array;
  }
  /* }}} */
--- 629,634 ----
***************
*** 798,803 ****
--- 797,804 ----
  
  /* {{{ module init and shutdown */
  
+ 
+ 
  int apc_module_init(int module_number TSRMLS_DC)
  {
      /* apc initialization */
***************
*** 849,859 ****
      return 0;
  }
  
  int apc_module_shutdown(TSRMLS_D)
  {
      if (!APCG(initialized))
          return 0;
! 
      /* restore compilation */
      zend_compile_file = old_compile_file;
  
--- 850,868 ----
      return 0;
  }
  
+ #define LESSSTAT 1
+ 
+ #ifdef LESSSTAT
+ extern void delete_stat_success_list ();  // Oct 17, 2011
+ #endif
+ 
  int apc_module_shutdown(TSRMLS_D)
  {
      if (!APCG(initialized))
          return 0;
! #ifdef LESSSTAT
!     delete_stat_success_list ();  // Oct 17, 2011
! #endif
      /* restore compilation */
      zend_compile_file = old_compile_file;
  
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC