cvs: pecl(INH_FIX) /apc INSTALL apc.c apc.php apc_cache.c apc_cache.h apc_compile.c apc_compile.h apc_debug.c apc_fcntl_win32.c apc_globals.h
apc_main.c apc_sma.c apc_sma.h config.m4 package.xml php_apc.c

From: Date: Sun, 12 Mar 2006 04:16:01 +0000
Subject: cvs: pecl(INH_FIX) /apc INSTALL apc.c apc.php apc_cache.c apc_cache.h apc_compile.c apc_compile.h apc_debug.c apc_fcntl_win32.c apc_globals.h
apc_main.c apc_sma.c apc_sma.h config.m4 package.xml php_apc.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-5423@lists.php.net to get a copy of this message
gopalv Sun Mar 12 04:16:01 2006 UTC Modified files: (Branch: INH_FIX) /pecl/apc INSTALL apc.c apc.php apc_cache.c apc_cache.h apc_compile.c apc_compile.h apc_debug.c apc_fcntl_win32.c apc_globals.h apc_main.c apc_sma.c apc_sma.h config.m4 package.xml php_apc.c Log: Merge from HEAD Re-do mangled naming using key values from hash fix default arg array corruption

http://cvs.php.net/viewcvs.cgi/pecl/apc/INSTALL?r1=3.48&r2=3.48.2.1&diff_format=u Index: pecl/apc/INSTALL diff -u pecl/apc/INSTALL:3.48 pecl/apc/INSTALL:3.48.2.1 --- pecl/apc/INSTALL:3.48 Thu Dec 15 07:50:25 2005 +++ pecl/apc/INSTALL Sun Mar 12 04:16:00 2006 @@ -4,6 +4,34 @@ This version of APC should work on every version of PHP from 4.3.0 to PHP 5.1.x. +CVS Instructions +---------------- +Building from CVS can be done like this: + + cvs -d :pserver:cvsread@cvs.php.net:/repository login + Password: phpfi + cvs -d :pserver:cvsread@cvs.php.net:/repository co pecl/apc + cd pecl/apc + phpize + ./configure --enable-apc-mmap --with-apxs --with-php-config=/usr/local/php/bin/php-config + make + make install + +Suggested Configuration (in your php.ini file) +---------------------------------------------- + extension=apc.so + apc.enabled=1 + apc.shm_segments=1 + apc.optimization=0 + apc.shm_size=128 + apc.ttl=7200 + apc.user_ttl=7200 + apc.num_files_hint=1024 + apc.mmap_file_mask=/tmp/apc.XXXXXX + apc.enable_cli=1 + +These are fully described at the bottom of this file. + PHP 4 Optimization ------------------ If you are trying to get every little bit of speed out of PHP4+APC, you need @@ -223,6 +251,11 @@ many thousands of source files. (Default: 1000) + apc.user_entries_hint Just like num_files_hint, a "hint" about the number + of distinct user cache variables to store. + Set to zero or omit if you're not sure; + (Default: 100) + apc.ttl The number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry. Leaving this at zero @@ -231,6 +264,15 @@ cached. (Default: 0) + apc.user_ttl The number of seconds a user cache entry is allowed + to idle in a slot in case this cache entry slot is + needed by another entry. Leaving this at zero + means that your cache could potentially fill up + with stale entries while newer entries won't be + cached. + (Default: 0) + + apc.gc_ttl The number of seconds that a cache entry may remain on the garbage-collection list. This value provides a failsafe in the event that a server @@ -271,7 +313,7 @@ kernel's /dev/zero interface to anonymous mmap'ed memory. Leaving it undefined will force an anonymous mmap. - (Default: "") + (Default: "") apc.slam_defense On very busy servers whenever you start the server or modify files you can create a race of many processes @@ -317,3 +359,8 @@ apc.max_file_size Prevents large files from being cached. (Default: 1M) + + apc.stat Whether to stat the main script file and the fullpath + includes. If you turn this off you will need to restart + your server in order to update scripts. + (Default: 1) http://cvs.php.net/viewcvs.cgi/pecl/apc/apc.c?r1=3.8&r2=3.8.2.1&diff_format=u Index: pecl/apc/apc.c diff -u pecl/apc/apc.c:3.8 pecl/apc/apc.c:3.8.2.1 --- pecl/apc/apc.c:3.8 Mon Jul 18 05:14:02 2005 +++ pecl/apc/apc.c Sun Mar 12 04:16:00 2006 @@ -29,7 +29,7 @@ */ -/* $Id: apc.c,v 3.8 2005/07/18 05:14:02 rasmus Exp $ */ +/* $Id: apc.c,v 3.8.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc.h" #include <regex.h> /* for POSIX regular expressions */ @@ -294,6 +294,10 @@ assert(filename && buf); + if (IS_ABSOLUTE_PATH(filename, strlen(filename)) && apc_stat(filename, buf) == 0) { + return 0; + } + paths = apc_tokenize(path, DEFAULT_DIR_SEPARATOR); if (!paths) return -1; http://cvs.php.net/viewcvs.cgi/pecl/apc/apc.php?r1=3.47&r2=3.47.2.1&diff_format=u Index: pecl/apc/apc.php diff -u pecl/apc/apc.php:3.47 pecl/apc/apc.php:3.47.2.1 --- pecl/apc/apc.php:3.47 Thu Sep 15 18:26:15 2005 +++ pecl/apc/apc.php Sun Mar 12 04:16:00 2006 @@ -22,7 +22,7 @@ */ -$VERSION='$Id: apc.php,v 3.47 2005/09/15 18:26:15 sniper Exp $'; +$VERSION='$Id: apc.php,v 3.47.2.1 2006/03/12 04:16:00 gopalv Exp $'; ////////// READ OPTIONAL CONFIGURATION FILE //////////// if (file_exists("apc.conf.php")) include("apc.conf.php"); @@ -167,14 +167,14 @@ } } -// clear cache -if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) { - apc_clear_cache(); -} // select cache mode if ($AUTHENTICATED && $MYREQUEST['OB'] == OB_USER_CACHE) { $cache_mode='user'; } +// clear cache +if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) { + apc_clear_cache($cache_mode); +} if(!$cache=@apc_cache_info($cache_mode)) { @@ -188,7 +188,29 @@ // header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); // HTTP/1.0 +header("Pragma: no-cache"); // HTTP/1.0 + +function duration($ts) { + global $time; + $years = (int)((($time - $ts)/(7*86400))/52.177457); + $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400)); + $weeks = (int)(($rem)/(7*86400)); + $days = (int)(($rem)/86400) - $weeks*7; + $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24; + $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60; + $str = ''; + if($years==1) $str .= "$years year, "; + if($years>1) $str .= "$years years, "; + if($weeks==1) $str .= "$weeks week, "; + if($weeks>1) $str .= "$weeks weeks, "; + if($days==1) $str .= "$days day,"; + if($days>1) $str .= "$days days,"; + if($hours == 1) $str .= " $hours hour and"; + if($hours>1) $str .= " $hours hours and"; + if($mins == 1) $str .= " 1 minute"; + else $str .= " $mins minutes"; + return $str; +} // create graphics // @@ -284,7 +306,7 @@ $size = GRAPH_SIZE; // image size if ($MYREQUEST['IMG']==3) - $image = imagecreate(2*$size+50, $size+10); + $image = imagecreate(2*$size+150, $size+10); else $image = imagecreate($size+50, $size+10); @@ -357,7 +379,7 @@ $y=1; $j=1; - // This block of code creates the pie chart. It is a lot more complex than you + // This block of code creates the bar chart. It is a lot more complex than you // would expect because we try to visualize any memory fragmentation as well. for($i=0; $i<$mem['num_seg']; $i++) { $ptr = 0; @@ -365,13 +387,19 @@ foreach($free as $block) { if($block['offset']!=$ptr) { // Used block $h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s; - if ($h>0) - fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j++); + if ($h>0) { + $j++; + if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j); + else fill_box($image,$x,$y,50,$h,$col_black,$col_red); + } $y+=$h; } $h=(GRAPH_SIZE-5)*($block['size'])/$s; - if ($h>0) - fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j++); + if ($h>0) { + $j++; + if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j); + else fill_box($image,$x,$y,50,$h,$col_black,$col_green); + } $y+=$h; $ptr = $block['offset']+$block['size']; } @@ -383,6 +411,13 @@ } } break; + case 4: + $s=$cache['num_hits']+$cache['num_misses']; + $a=$cache['num_hits']; + + fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$cache['num_hits']*100/$s)); + fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$cache['num_misses']*100/$s)); + break; } header("Content-type: image/png"); @@ -607,7 +642,7 @@ div.graph table td { padding:0.2em 1em 0.4em 1em; } div.div1,div.div2 { margin-bottom:1em; width:35em; } -div.div3 { position:absolute; left:37em; top:1em; width:580px; } +div.div3 { position:absolute; left:40em; top:1em; width:580px; } //div.div3 { position:absolute; left:37em; top:1em; right:1em; } div.sorting { margin:1.5em 0em 1.5em 2em } @@ -679,7 +714,7 @@ if ($AUTHENTICATED) { echo <<<EOB - <li><a class="aright" href="$MY_SELF&CC=1&OB={$MYREQUEST['OB']}" onClick="javascipt:return confirm('Are you sure?');">Clear Cache</a></li> + <li><a class="aright" href="$MY_SELF&CC=1&OB={$MYREQUEST['OB']}" onClick="javascipt:return confirm('Are you sure?');">Clear $cache_mode Cache</a></li> EOB; } echo <<<EOB @@ -732,9 +767,10 @@ <tr class=tr-1><td class=td-0>Request Rate</td><td>$req_rate cache requests/second</td></tr> <tr class=tr-0><td class=td-0>Time To Live</td><td>{$cache['ttl']}</td></tr> <tr class=tr-1><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size</td></tr> + <tr class=tr-0><td class=td-0>Cache full count</td><td>{$cache['expunges']}</td></tr> EOB; - echo - '<tr class=tr-0><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>'; + echo '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>'; + echo '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>'; echo <<<EOB </tbody></table> </div> @@ -744,7 +780,7 @@ $j = 0; foreach (ini_get_all('apc') as $k => $v) { - echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",$v['local_value'],"</td></tr>\n"; + echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n"; $j = 1 - $j; } @@ -793,7 +829,7 @@ EOB; // Fragementation: (freeseg - 1) / total_seg - $nseg = $freeseg = 0; + $nseg = $freeseg = $fragsize = $freetotal = 0; for($i=0; $i<$mem['num_seg']; $i++) { $ptr = 0; foreach($mem['block_lists'][$i] as $block) { @@ -801,18 +837,21 @@ ++$nseg; } $ptr = $block['offset'] + $block['size']; + /* Only consider blocks <5M for the fragmentation % */ + if($block['size']<(5*1024*1024)) $fragsize+=$block['size']; + $freetotal+=$block['size']; } $freeseg += count($mem['block_lists'][$i]); } if ($freeseg > 1) { - $frag = sprintf("%.2f%%", (($freeseg - 1) / ($freeseg + $nseg)) * 100); + $frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg); } else { $frag = "0%"; } if (graphics_avail()) { - $size='width='.(2*GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10); + $size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10); echo <<<EOB <img alt="" $size src="$PHP_SELF?IMG=3&$time"> EOB; @@ -821,6 +860,16 @@ </br>Fragmentation: $frag </td> </tr> +EOB; + if(isset($mem['adist'])) { + foreach($mem['adist'] as $i=>$v) { + $cur = pow(2,$i); $nxt = pow(2,$i+1)-1; + if($i==0) $range = "1"; + else $range = "$cur - $nxt"; + echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n"; + } + } + echo <<<EOB </tbody></table> </div> EOB; http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_cache.c?r1=3.99&r2=3.99.2.1&diff_format=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.99 pecl/apc/apc_cache.c:3.99.2.1 --- pecl/apc/apc_cache.c:3.99 Wed Nov 16 15:48:07 2005 +++ pecl/apc/apc_cache.c Sun Mar 12 04:16:00 2006 @@ -28,16 +28,19 @@ */ -/* $Id: apc_cache.c,v 3.99 2005/11/16 15:48:07 iliaa Exp $ */ +/* $Id: apc_cache.c,v 3.99.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc_cache.h" #include "apc_lock.h" #include "apc_sma.h" #include "apc_globals.h" #include "SAPI.h" +#include "ext/standard/php_var.h" /* TODO: rehash when load factor exceeds threshold */ +#define CHECK(p) { if ((p) == NULL) return NULL; } + /* {{{ locking macros */ #define CREATE_LOCK apc_lck_create(NULL, 0, 1) #define DESTROY_LOCK(c) apc_lck_destroy(c->lock) @@ -67,6 +70,8 @@ int num_misses; /* total unsuccessful hits in cache */ slot_t* deleted_list; /* linked list of to-be-deleted slots */ time_t start_time; /* time the above counters were reset */ + int expunges; /* total number of expunges */ + zend_bool busy; /* Flag to tell clients when we are busy cleaning the cache */ }; /* }}} */ @@ -96,46 +101,52 @@ /* {{{ string_nhash_8 */ static unsigned int string_nhash_8(const char *s, size_t len) { - register const unsigned int *iv = (const unsigned int *)s; - register unsigned int h = 0; - register unsigned int n; - - if (len > 3) { - if (len & 3) { - h = *(unsigned int *)(s + len - 4); - } - len /= 4; - for (n = 0; n < len; n++) { - h+= iv[n]; - h = (h << 7) | (h >> (32 - 7)); - } - } else { - if (len > 1) { - h += s[1]; - if (len == 3) h += s[2]; - } - h += s[0]; - } - h ^= (h >> 13); - h ^= (h >> 7); - return h; + register const unsigned int *iv = (const unsigned int *)s; + register unsigned int h = 0; + register unsigned int n; + + if(len > 3) { + if(len & 3) { + h = *(unsigned int *)(s + len - 4); + } + len /= 4; + for (n = 0; n < len; n++) { + h+= iv[n]; + h = (h << 7) | (h >> (32 - 7)); + } + } else { + if (len > 1) { + h += s[1]; + if (len == 3) h += s[2]; + } + h += s[0]; + } + h ^= (h >> 13); + h ^= (h >> 7); + return h; } /* }}} */ /* {{{ make_slot */ slot_t* make_slot(apc_cache_key_t key, apc_cache_entry_t* value, slot_t* next, time_t t) { - char *identifier; slot_t* p = apc_sma_malloc(sizeof(slot_t)); if (!p) return NULL; if(value->type == APC_CACHE_ENTRY_USER) { - identifier = (char*) apc_xstrdup(key.data.user.identifier, apc_sma_malloc); + char *identifier = (char*) apc_xstrdup(key.data.user.identifier, apc_sma_malloc); if (!identifier) { apc_sma_free(p); return NULL; } key.data.user.identifier = identifier; + } else if(key.type == APC_CACHE_KEY_FPFILE) { + char *fullpath = (char*) apc_xstrdup(key.data.fpfile.fullpath, apc_sma_malloc); + if (!fullpath) { + apc_sma_free(p); + return NULL; + } + key.data.fpfile.fullpath = fullpath; } p->key = key; p->value = value; @@ -153,6 +164,8 @@ { if(slot->value->type == APC_CACHE_ENTRY_USER) { apc_sma_free(slot->key.data.user.identifier); + } else if(slot->key.type == APC_CACHE_KEY_FPFILE) { + apc_sma_free(slot->key.data.fpfile.fullpath); } apc_cache_free_entry(slot->value); apc_sma_free(slot); @@ -278,6 +291,8 @@ cache->header->num_misses = 0; cache->header->deleted_list = NULL; cache->header->start_time = time(NULL); + cache->header->expunges = 0; + cache->header->busy = 0; cache->slots = (slot_t**) (((char*) cache->shmaddr) + sizeof(header_t)); cache->num_slots = num_slots; @@ -309,10 +324,11 @@ if(!cache) return; LOCK(cache); - + cache->header->busy = 1; cache->header->num_hits = 0; cache->header->num_misses = 0; cache->header->start_time = time(NULL); + cache->header->expunges = 0; for (i = 0; i < cache->num_slots; i++) { slot_t* p = cache->slots[i]; @@ -322,6 +338,7 @@ cache->slots[i] = NULL; } + cache->header->busy = 0; UNLOCK(cache); } /* }}} */ @@ -330,46 +347,70 @@ void apc_cache_expunge(apc_cache_t* cache, time_t t) { int i; - slot_t **p; - /* - * We don't do any cache cleanup here unless the ttl for the cache - * has been set. For the user cache that is slightly confusing since - * we have the individual entry ttl's we can look at, but that would be - * too much work. So if you want the user cache expunged, set a high - * default apc.user_ttl and still provide a specific ttl for each entry - * on insert - */ - if(!cache || (cache && !cache->ttl)) return; + if(!cache) return; - LOCK(cache); - for (i = 0; i < cache->num_slots; i++) { - p = &cache->slots[i]; - while(*p) { - /* - * For the user cache we look at the individual entry ttl values - * and if not set fall back to the default ttl for the user cache - */ - if((*p)->value->type == APC_CACHE_ENTRY_USER) { - if((*p)->value->data.user.ttl) { - if((*p)->creation_time + (*p)->value->data.user.ttl < t) { - remove_slot(cache, p); - continue; - } - } else if(cache->ttl) { - if((*p)->creation_time + cache->ttl < t) { - remove_slot(cache, p); - continue; + if(!cache->ttl) { + /* + * If cache->ttl is not set, we wipe out the entire cache when + * we run out of space. + */ + LOCK(cache); + cache->header->busy = 1; + cache->header->expunges++; + for (i = 0; i < cache->num_slots; i++) { + slot_t* p = cache->slots[i]; + while (p) { + remove_slot(cache, &p); + } + cache->slots[i] = NULL; + } + cache->header->busy = 0; + UNLOCK(cache); + } else { + slot_t **p; + + /* + * If the ttl for the cache is set we walk through and delete stale + * entries. For the user cache that is slightly confusing since + * we have the individual entry ttl's we can look at, but that would be + * too much work. So if you want the user cache expunged, set a high + * default apc.user_ttl and still provide a specific ttl for each entry + * on insert + */ + + LOCK(cache); + cache->header->busy = 1; + cache->header->expunges++; + for (i = 0; i < cache->num_slots; i++) { + p = &cache->slots[i]; + while(*p) { + /* + * For the user cache we look at the individual entry ttl values + * and if not set fall back to the default ttl for the user cache + */ + if((*p)->value->type == APC_CACHE_ENTRY_USER) { + if((*p)->value->data.user.ttl) { + if((*p)->creation_time + (*p)->value->data.user.ttl < t) { + remove_slot(cache, p); + continue; + } + } else if(cache->ttl) { + if((*p)->creation_time + cache->ttl < t) { + remove_slot(cache, p); + continue; + } } + } else if((*p)->access_time < (t - cache->ttl)) { + remove_slot(cache, p); + continue; } - } else if((*p)->access_time < (t - cache->ttl)) { - remove_slot(cache, p); - continue; + p = &(*p)->next; } - p = &(*p)->next; } + cache->header->busy = 0; + UNLOCK(cache); } - UNLOCK(cache); } /* }}} */ @@ -385,23 +426,39 @@ return 0; } +#ifdef __DEBUG_APC__ + fprintf(stderr,"Inserting [%s]\n", value->data.file.filename); +#endif + LOCK(cache); process_pending_removals(cache); - slot = &cache->slots[hash(key) % cache->num_slots]; + if(key.type == APC_CACHE_KEY_FILE) slot = &cache->slots[hash(key) % cache->num_slots]; + else slot = &cache->slots[string_nhash_8(key.data.fpfile.fullpath, key.data.fpfile.fullpath_len) % cache->num_slots]; - while (*slot) { - if (key_equals((*slot)->key.data.file, key.data.file)) { - /* If existing slot for the same device+inode is different, remove it and insert the new version */ - if ((*slot)->key.mtime != key.mtime) { + while(*slot) { + if(key.type == APC_CACHE_KEY_FILE) { + if(key_equals((*slot)->key.data.file, key.data.file)) { + /* If existing slot for the same device+inode is different, remove it and insert the new version */ + if ((*slot)->key.mtime != key.mtime) { + remove_slot(cache, slot); + break; + } + UNLOCK(cache); + return 0; + } else if(cache->ttl && (*slot)->access_time < (t - cache->ttl)) { + remove_slot(cache, slot); + continue; + } + } else { /* APC_CACHE_KEY_FPFILE */ + if(!memcmp((*slot)->key.data.fpfile.fullpath, key.data.fpfile.fullpath, key.data.fpfile.fullpath_len)) { + /* Hrm.. it's already here, remove it and insert new one */ remove_slot(cache, slot); break; + } else if(cache->ttl && (*slot)->access_time < (t - cache->ttl)) { + remove_slot(cache, slot); + continue; } - UNLOCK(cache); - return 0; - } else if(cache->ttl && (*slot)->access_time < (t - cache->ttl)) { - remove_slot(cache, slot); - continue; } slot = &(*slot)->next; } @@ -465,6 +522,9 @@ UNLOCK(cache); return 0; } + if (APCG(mem_size_ptr) != NULL) { + value->mem_size = *APCG(mem_size_ptr); + } UNLOCK(cache); return 1; @@ -478,23 +538,35 @@ LOCK(cache); - slot = &cache->slots[hash(key) % cache->num_slots]; + if(key.type == APC_CACHE_KEY_FILE) slot = &cache->slots[hash(key) % cache->num_slots]; + else slot = &cache->slots[string_nhash_8(key.data.fpfile.fullpath, key.data.fpfile.fullpath_len) % cache->num_slots]; while (*slot) { - if (key_equals((*slot)->key.data.file, key.data.file)) { - if ((*slot)->key.mtime < key.mtime) { - remove_slot(cache, slot); - break; + if(key.type == APC_CACHE_KEY_FILE) { + if(key_equals((*slot)->key.data.file, key.data.file)) { + if((*slot)->key.mtime != key.mtime) { + remove_slot(cache, slot); + break; + } + (*slot)->num_hits++; + (*slot)->value->ref_count++; + (*slot)->access_time = t; + prevent_garbage_collection((*slot)->value); + cache->header->num_hits++; + UNLOCK(cache); + return (*slot)->value; + } + } else { /* APC_CACHE_KEY_FPFILE */ + if(!memcmp((*slot)->key.data.fpfile.fullpath, key.data.fpfile.fullpath, key.data.fpfile.fullpath_len)) { + /* TTL Check ? */ + (*slot)->num_hits++; + (*slot)->value->ref_count++; + (*slot)->access_time = t; + prevent_garbage_collection((*slot)->value); + cache->header->num_hits++; + UNLOCK(cache); + return (*slot)->value; } - - (*slot)->num_hits++; - (*slot)->value->ref_count++; - (*slot)->access_time = t; - prevent_garbage_collection((*slot)->value); - - cache->header->num_hits++; - UNLOCK(cache); - return (*slot)->value; } slot = &(*slot)->next; } @@ -579,16 +651,25 @@ TSRMLS_DC) { struct stat buf, *tmp_buf=NULL; + int len; assert(key != NULL); if (!filename || !SG(request_info).path_translated) { #ifdef __DEBUG_APC__ - fprintf(stderr,"No filename and no path_translated - bailing\n"); + fprintf(stderr,"No filename and no path_translated - bailing\n"); #endif return 0; } + len = strlen(filename); + if(APCG(fpstat)==0 && IS_ABSOLUTE_PATH(filename,len)) { + key->data.fpfile.fullpath = filename; + key->data.fpfile.fullpath_len = len; + key->mtime = t; + key->type = APC_CACHE_KEY_FPFILE; + return 1; + } if(!strcmp(SG(request_info).path_translated, filename)) { tmp_buf = sapi_get_stat(TSRMLS_C); /* Apache has already done this stat() for us */ @@ -596,7 +677,7 @@ if(tmp_buf) { buf = *tmp_buf; } else { - if (apc_stat(filename, &buf) != 0 && apc_stat_paths(filename, include_path, &buf) != 0) { + if (apc_stat_paths(filename, include_path, &buf) != 0) { #ifdef __DEBUG_APC__ fprintf(stderr,"Stat failed %s - bailing (%s) (%d)\n",filename,SG(request_info).path_translated); #endif @@ -604,11 +685,11 @@ } } - if (APCG(max_file_size) < buf.st_size) { + if(APCG(max_file_size) < buf.st_size) { #ifdef __DEBUG_APC__ - fprintf(stderr,"File is too big %s (%d - %ld) - bailing\n",filename,t,buf.st_size); + fprintf(stderr,"File is too big %s (%d - %ld) - bailing\n",filename,t,buf.st_size); #endif - return 0; + return 0; } /* @@ -625,10 +706,10 @@ */ if(APCG(file_update_protection) && (t - buf.st_mtime < APCG(file_update_protection))) { #ifdef __DEBUG_APC__ - fprintf(stderr,"File is too new %s (%d - %d) - bailing\n",filename,t,buf.st_mtime); + fprintf(stderr,"File is too new %s (%d - %d) - bailing\n",filename,t,buf.st_mtime); #endif - return 0; - } + return 0; + } key->data.file.device = buf.st_dev; key->data.file.inode = buf.st_ino; @@ -646,6 +727,7 @@ */ /* key->mtime = (buf.st_ctime > buf.st_mtime) ? buf.st_ctime : buf.st_mtime; */ key->mtime = buf.st_mtime; + key->type = APC_CACHE_KEY_FILE; return 1; } /* }}} */ @@ -661,16 +743,7 @@ key->data.user.identifier = identifier; key->data.user.identifier_len = identifier_len; key->mtime = t; - return 1; -} -/* }}} */ - -/* {{{ apc_cache_free_user_key */ -int apc_cache_free_user_key(apc_cache_key_t* key) -{ - assert(key != NULL); - - apc_sma_free(key->data.user.identifier); + key->type = APC_CACHE_KEY_USER; return 1; } /* }}} */ @@ -689,11 +762,14 @@ entry->data.file.filename = apc_xstrdup(filename, apc_sma_malloc); if(!entry->data.file.filename) { #ifdef __DEBUG_APC__ - fprintf(stderr,"apc_cache_make_file_entry: entry->data.file.filename is NULL - bailing\n"); + fprintf(stderr,"apc_cache_make_file_entry: entry->data.file.filename is NULL - bailing\n"); #endif apc_sma_free(entry); return NULL; } +#ifdef __DEBUG_APC__ + fprintf(stderr,"apc_cache_make_file_entry: entry->data.file.filename is [%s]\n",entry->data.file.filename); +#endif entry->data.file.op_array = op_array; entry->data.file.functions = functions; entry->data.file.classes = classes; @@ -704,6 +780,74 @@ } /* }}} */ +/* {{{ apc_cache_store_zval */ +zval* apc_cache_store_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate) +{ + smart_str buf = {0}; + php_serialize_data_t var_hash; + + if((src->type & ~IS_CONSTANT_INDEX) == IS_OBJECT) { + TSRMLS_FETCH(); + + if(!dst) { + CHECK(dst = (zval*) allocate(sizeof(zval))); + } + + PHP_VAR_SERIALIZE_INIT(var_hash); + php_var_serialize(&buf, (zval**)&src, &var_hash TSRMLS_CC); + PHP_VAR_SERIALIZE_DESTROY(var_hash); + + dst->type = IS_NULL; /* in case we fail */ + if(buf.c) { + dst->type = src->type & ~IS_CONSTANT_INDEX; + dst->value.str.len = buf.len; + CHECK(dst->value.str.val = apc_xmemcpy(buf.c, buf.len+1, allocate)); + dst->type = src->type; + } + return dst; + } else { + return apc_copy_zval(dst, src, allocate, deallocate); + } +} +/* }}} */ + +/* {{{ apc_cache_fetch_zval */ +zval* apc_cache_fetch_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate) +{ + if((src->type & ~IS_CONSTANT_INDEX) == IS_OBJECT) { + php_unserialize_data_t var_hash; + const unsigned char *p = (unsigned char*)Z_STRVAL_P(src); + TSRMLS_FETCH(); + + PHP_VAR_UNSERIALIZE_INIT(var_hash); + if(!php_var_unserialize(&dst, &p, p + Z_STRLEN_P(src), &var_hash TSRMLS_CC)) { + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + zval_dtor(dst); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes", (long)((char*)p - Z_STRVAL_P(src)), Z_STRLEN_P(src)); + dst->type = IS_NULL; + } + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + return dst; + } else { + return apc_copy_zval(dst, src, allocate, deallocate); + } +} +/* }}} */ + +/* {{{ apc_cache_free_zval */ +void apc_cache_free_zval(zval* src, apc_free_t deallocate) +{ + if ((src->type & ~IS_CONSTANT_INDEX) == IS_OBJECT) { + if (src->value.str.val) { + deallocate(src->value.str.val); + } + deallocate(src); + } else { + apc_free_zval(src, deallocate); + } +} +/* }}} */ + /* {{{ apc_cache_make_user_entry */ apc_cache_entry_t* apc_cache_make_user_entry(const char* info, int info_len, const zval* val, const unsigned int ttl) { @@ -718,7 +862,7 @@ apc_sma_free(entry); return NULL; } - entry->data.user.val = apc_copy_zval(NULL, val, apc_sma_malloc, apc_sma_free); + entry->data.user.val = apc_cache_store_zval(NULL, val, apc_sma_malloc, apc_sma_free); if(!entry->data.user.val) { apc_sma_free(entry->data.user.info); apc_sma_free(entry); @@ -747,7 +891,7 @@ break; case APC_CACHE_ENTRY_USER: apc_sma_free(entry->data.user.info); - apc_free_zval(entry->data.user.val, apc_sma_free); + apc_cache_free_zval(entry->data.user.val, apc_sma_free); break; } apc_sma_free(entry); @@ -778,6 +922,7 @@ info->list = NULL; info->deleted_list = NULL; info->start_time = cache->header->start_time; + info->expunges = cache->header->expunges; /* For each hashtable slot */ for (i = 0; i < info->num_slots; i++) { @@ -787,8 +932,13 @@ if(p->value->type == APC_CACHE_ENTRY_FILE) { link->data.file.filename = apc_xstrdup(p->value->data.file.filename, apc_emalloc); - link->data.file.device = p->key.data.file.device; - link->data.file.inode = p->key.data.file.inode; + if(p->key.type == APC_CACHE_KEY_FILE) { + link->data.file.device = p->key.data.file.device; + link->data.file.inode = p->key.data.file.inode; + } else { /* This is a no-stat fullpath file entry */ + link->data.file.device = 0; + link->data.file.inode = 0; + } link->type = APC_CACHE_ENTRY_FILE; } else if(p->value->type == APC_CACHE_ENTRY_USER) { link->data.user.info = apc_xmemcpy(p->value->data.user.info, p->value->data.user.info_len, apc_emalloc); @@ -810,12 +960,17 @@ /* For each slot pending deletion */ for (p = cache->header->deleted_list; p != NULL; p = p->next) { apc_cache_link_t* link = (apc_cache_link_t*) - apc_emalloc(sizeof(apc_cache_link_t)); + apc_emalloc(sizeof(apc_cache_link_t)); if(p->value->type == APC_CACHE_ENTRY_FILE) { link->data.file.filename = apc_xstrdup(p->value->data.file.filename, apc_emalloc); - link->data.file.device = p->key.data.file.device; - link->data.file.inode = p->key.data.file.inode; + if(p->key.type == APC_CACHE_KEY_FILE) { + link->data.file.device = p->key.data.file.device; + link->data.file.inode = p->key.data.file.inode; + } else { /* This is a no-stat fullpath file entry */ + link->data.file.device = 0; + link->data.file.inode = 0; + } link->type = APC_CACHE_ENTRY_FILE; } else if(p->value->type == APC_CACHE_ENTRY_USER) { link->data.user.info = apc_xmemcpy(p->value->data.user.info, p->value->data.user.info_len, apc_emalloc); @@ -853,6 +1008,20 @@ } /* }}} */ +/* {{{ apc_cache_unlock */ +void apc_cache_unlock(apc_cache_t* cache) +{ + UNLOCK(cache); +} +/* }}} */ + +/* {{{ apc_cache_busy */ +zend_bool apc_cache_busy(apc_cache_t* cache) +{ + return cache->header->busy; +} +/* }}} */ + /* * Local variables: * tab-width: 4 http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_cache.h?r1=3.30&r2=3.30.2.1&diff_format=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.30 pecl/apc/apc_cache.h:3.30.2.1 --- pecl/apc/apc_cache.h:3.30 Wed Nov 16 15:48:08 2005 +++ pecl/apc/apc_cache.h Sun Mar 12 04:16:00 2006 @@ -26,7 +26,7 @@ */ -/* $Id: apc_cache.h,v 3.30 2005/11/16 15:48:08 iliaa Exp $ */ +/* $Id: apc_cache.h,v 3.30.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -39,9 +39,14 @@ #include "apc.h" #include "apc_compile.h" -#define APC_CACHE_ENTRY_FILE 1 -#define APC_CACHE_ENTRY_USER 2 +#define APC_CACHE_ENTRY_FILE 1 +#define APC_CACHE_ENTRY_USER 2 +#define APC_CACHE_KEY_FILE 1 +#define APC_CACHE_KEY_USER 2 +#define APC_CACHE_KEY_FPFILE 3 + +/* {{{ struct definition: apc_cache_key_t */ #define T apc_cache_t* typedef struct apc_cache_t apc_cache_t; /* opaque cache type */ @@ -52,18 +57,23 @@ } file; struct { char *identifier; - int identifier_len; + int identifier_len; } user; + struct { + char *fullpath; + int fullpath_len; + } fpfile; } apc_cache_key_data_t; -/* {{{ struct definition: apc_cache_key_t */ typedef struct apc_cache_key_t apc_cache_key_t; struct apc_cache_key_t { apc_cache_key_data_t data; - int mtime; /* the mtime of this cached entry */ + time_t mtime; /* the mtime of this cached entry */ + unsigned char type; }; /* }}} */ +/* {{{ struct definition: apc_cache_entry_t */ typedef union _apc_cache_entry_value_t { struct { char *filename; /* absolute path to source file */ @@ -73,13 +83,12 @@ } file; struct { char *info; - int info_len; + int info_len; zval *val; unsigned int ttl; } user; } apc_cache_entry_value_t; -/* {{{ struct definition: apc_cache_entry_t */ typedef struct apc_cache_entry_t apc_cache_entry_t; struct apc_cache_entry_t { apc_cache_entry_value_t data; @@ -160,6 +169,12 @@ */ extern int apc_cache_user_delete(apc_cache_t* cache, char *strkey, int keylen); +/* apc_cach_fetch_zval takes a zval in the cache and reconstructs a runtime + * zval from it. + * + */ +zval* apc_cache_fetch_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate); + /* * apc_cache_release decrements the reference count associated with a cache * entry. Calling apc_cache_find automatically increments the reference count, @@ -208,7 +223,6 @@ extern apc_cache_entry_t* apc_cache_make_user_entry(const char* info, int info_len, const zval *val, const unsigned int ttl); extern int apc_cache_make_user_key(apc_cache_key_t* key, char* identifier, int identifier_len, const time_t t); -extern int apc_cache_free_user_key(apc_cache_key_t* key); /* * Frees all memory associated with an object returned by apc_cache_make_entry @@ -256,12 +270,15 @@ apc_cache_link_t* list; apc_cache_link_t* deleted_list; time_t start_time; + int expunges; }; /* }}} */ extern apc_cache_info_t* apc_cache_info(T cache); extern void apc_cache_free_info(apc_cache_info_t* info); extern void apc_cache_expunge(apc_cache_t* cache, time_t t); +extern void apc_cache_unlock(apc_cache_t* cache); +extern zend_bool apc_cache_busy(apc_cache_t* cache); #undef T #endif http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_compile.c?r1=3.31.2.1&r2=3.31.2.2&diff_format=u Index: pecl/apc/apc_compile.c diff -u pecl/apc/apc_compile.c:3.31.2.1 pecl/apc/apc_compile.c:3.31.2.2 --- pecl/apc/apc_compile.c:3.31.2.1 Thu Dec 15 08:19:09 2005 +++ pecl/apc/apc_compile.c Sun Mar 12 04:16:00 2006 @@ -28,7 +28,7 @@ */ -/* $Id: apc_compile.c,v 3.31.2.1 2005/12/15 08:19:09 rasmus Exp $ */ +/* $Id: apc_compile.c,v 3.31.2.2 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc_compile.h" #include "apc_globals.h" @@ -626,6 +626,7 @@ static zend_class_entry* my_copy_class_entry(zend_class_entry* dst, zend_class_entry* src, apc_malloc_t allocate, apc_free_t deallocate) { int local_dst_alloc = 0; + int i = 0; assert(src != NULL); @@ -648,6 +649,7 @@ dst->doc_comment = NULL; memset(&dst->properties_info, 0, sizeof(dst->properties_info)); memset(&dst->constants_table, 0, sizeof(dst->constants_table)); + memset(&dst->default_static_members, 0, sizeof(dst->default_static_members)); #endif if (src->name) { @@ -683,7 +685,18 @@ /* the interfaces are populated at runtime using ADD_INTERFACE */ dst->interfaces = NULL; - + + /* the current count includes inherited interfaces as well, + the real dynamic ones are the first <n> which are zero'd + out in zend_do_end_class_declaration */ + for(i = 0 ; i < src->num_interfaces ; i++) { + if(src->interfaces[i]) + { + dst->num_interfaces = i; + break; + } + } + /* these will either be set inside my_fixup_hashtable or * they will be copied out from parent inside zend_do_inheritance */ @@ -692,7 +705,13 @@ dst->clone = NULL; dst->__get = NULL; dst->__set = NULL; + dst->__unset = NULL; + dst->__isset = NULL; dst->__call = NULL; + + /* unset function proxies */ + dst->serialize_func = NULL; + dst->unserialize_func = NULL; my_fixup_hashtable(&dst->function_table, (ht_fixup_fun_t)my_fixup_function, src, dst); #endif @@ -718,8 +737,20 @@ src))) { goto cleanup; } - - if(!(dst->static_members = my_copy_hashtable_ex(NULL, + + if(!my_copy_hashtable_ex(&dst->default_static_members, + &src->default_static_members, + (ht_copy_fun_t) my_copy_zval_ptr, + (ht_free_fun_t) my_free_zval_ptr, + 1, + allocate, deallocate, + (ht_check_copy_fun_t) my_check_copy_static_member, + src)) { + goto cleanup; + } + if(src->static_members != &src->default_static_members) + { + if(!(dst->static_members = my_copy_hashtable_ex(NULL, src->static_members, (ht_copy_fun_t) my_copy_zval_ptr, (ht_free_fun_t) my_free_zval_ptr, @@ -727,7 +758,12 @@ allocate, deallocate, (ht_check_copy_fun_t) my_check_copy_static_member, src))) { - goto cleanup; + goto cleanup; + } + } + else + { + dst->static_members = &dst->default_static_members; } if(!(my_copy_hashtable(&dst->constants_table, @@ -798,7 +834,15 @@ #ifdef ZEND_ENGINE_2 if(dst->properties_info.arBuckets) my_destroy_hashtable(&dst->properties_info, (ht_free_fun_t) my_free_property_info, deallocate); - if(dst->static_members) my_free_hashtable(dst->static_members, (ht_free_fun_t) my_free_zval_ptr, deallocate); + if(dst->default_static_members.arBuckets) + { + my_destroy_hashtable(dst->static_members, (ht_free_fun_t) my_free_zval_ptr, deallocate); + } + if(dst->static_members != &(dst->default_static_members)) + { + my_destroy_hashtable(dst->static_members, (ht_free_fun_t) my_free_zval_ptr, deallocate); + deallocate(dst->static_members); + } if(dst->constants_table.arBuckets) my_destroy_hashtable(&dst->constants_table, (ht_free_fun_t) my_free_zval_ptr, deallocate); #endif if(local_dst_alloc) deallocate(dst); @@ -975,7 +1019,15 @@ #ifdef ZEND_ENGINE_2 #undef MAKE_NOP -#define MAKE_NOP(opline) { opline->opcode = ZEND_NOP; memset(&opline->result,0,sizeof(znode)); memset(&opline->op1,0,sizeof(znode)); memset(&opline->op2,0,sizeof(znode)); opline->result.op_type=opline->op1.op_type=opline->op2.op_type=IS_UNUSED; } +#define MAKE_NOP(opline) do { \ + opline->opcode = ZEND_NOP;\ + memset(&opline->result,0,sizeof(znode));\ + memset(&opline->op1,0,sizeof(znode));\ + memset(&opline->op2,0,sizeof(znode));\ + opline->result.op_type=\ + opline->op1.op_type=opline->op2.op_type=IS_UNUSED;\ + ZEND_VM_SET_OPCODE_HANDLER(opline);\ + }while(0) /* {{{ apc_fixup_op_array_jumps */ static void apc_fixup_op_array_jumps(zend_op_array *dst, zend_op_array *src ) @@ -998,8 +1050,35 @@ zo->op2.u.jmp_addr = dst->opcodes + (zo->op2.u.jmp_addr - src->opcodes); break; case ZEND_DECLARE_INHERITED_CLASS: + /* + Takes a bit to explain why I *don't* nuke the ops. + Technically this prevents double instantiation of a + class, but the problem is that the class name in the + CG(class_table) != class name stored in here. For + example + if($hello) + { + class BX extends A + { + } + } + else + { + class BX extends B + { + } + } + is pushed out as two different class names in the + CG(class_table), with corresponding declare inherited + classes inline to declare 'BX' depending on code path. + Therefore in that case, we do really need the fetch + & declare operations. Need more diving around in the + op_array code in Zend. + */ + /* if(pzo->opcode == ZEND_FETCH_CLASS) MAKE_NOP(pzo); MAKE_NOP(zo); + */ break; default: break; @@ -1157,7 +1236,7 @@ } } #endif - + return dst; cleanup_opcodes: @@ -1361,7 +1440,17 @@ array[i].parent_name = NULL; array[i].is_derived = is_derived_class(op_array, elem->name, elem->name_length); } + +#ifdef ZEND_ENGINE_2 + if(!(array[i].mangled_name = + apc_xmemcpy(key, key_size, allocate))) { + // TODO: cleanup code re-org, pools/arenas anyone ? + } + // or is that key_size-1 ? + array[i].mangled_name_len = key_size; +#endif + zend_hash_move_forward(CG(class_table)); } @@ -1541,10 +1630,16 @@ my_destroy_hashtable(&src->properties_info, (ht_free_fun_t) my_free_property_info, deallocate); - my_destroy_hashtable(src->static_members, + if(src->static_members) + { + my_destroy_hashtable(src->static_members, (ht_free_fun_t) my_free_zval_ptr, deallocate); - deallocate(src->static_members); + if(src->static_members != &(src->default_static_members)) + { + deallocate(src->static_members); + } + } my_destroy_hashtable(&src->constants_table, (ht_free_fun_t) my_free_zval_ptr, @@ -1739,12 +1834,89 @@ } /* }}} */ +#ifdef ZEND_ENGINE_2 +/* {{{ my_fetch_global_vars */ +void my_fetch_global_vars(zend_op_array* src TSRMLS_DC) +{ + /* all jit_initialization variables (like $_SERVER) are created + on demand due to a fetch_simple_variable called during parsing. + The code below fakes it and makes a call to is_auto_global. + */ + int i = 0; + for (i = 0; i < src->last; i++) + { + zend_op *opcode = src->opcodes+i; + if(opcode->op2.u.EA.type == ZEND_FETCH_GLOBAL && + opcode->op1.op_type == IS_CONST && + opcode->op1.u.constant.type == IS_STRING) + { + znode * varname = &opcode->op1; + if (varname->u.constant.value.str.val[0] == '_') { + (void)zend_is_auto_global(varname->u.constant.value.str.val, + varname->u.constant.value.str.len TSRMLS_CC); + } + } + } +} +/* }}} */ + +/* {{{ my_copy_default_args */ +static int my_copy_default_args(zend_op_array* dst, zend_op_array* src) +{ + int i; + int needcopy = 0; + if(src->num_args == src->required_num_args) + { + /* yay !, no default args */ + return 1; + } + for (i = 0; i < src->last; i++) + { + zend_op *opcode = src->opcodes+i; + if(opcode->opcode == ZEND_RECV_INIT && + opcode->op2.u.constant.type == IS_CONSTANT_ARRAY) + { + needcopy = 1; + break; + } + } + if(needcopy) + { + dst->opcodes = (zend_op*) apc_xmemcpy(src->opcodes, + sizeof(zend_op) * src->last, + apc_php_malloc); + for (i = 0; i < src->last; i++) + { + zend_op *opcode = src->opcodes+i; + if(opcode->opcode == ZEND_RECV_INIT && + opcode->op2.u.constant.type == IS_CONSTANT_ARRAY) + { + if(!(my_copy_zend_op(dst->opcodes+i, src->opcodes+i, + apc_php_malloc, apc_php_free))) + { + //TODO: cleanup code + } + } + } + + apc_fixup_op_array_jumps(dst,src); + } + return 1; +} +/* }}} */ +#endif + /* {{{ apc_copy_op_array_for_execution */ -zend_op_array* apc_copy_op_array_for_execution(zend_op_array* src) + +zend_op_array* apc_copy_op_array_for_execution(zend_op_array* src TSRMLS_DC) { zend_op_array* dst = (zend_op_array*) emalloc(sizeof(src[0])); memcpy(dst, src, sizeof(src[0])); dst->static_variables = my_copy_static_variables(src, apc_php_malloc, apc_php_free); +#ifdef ZEND_ENGINE_2 + my_fetch_global_vars(dst TSRMLS_CC); + my_copy_default_args(dst, src); +#endif /*check_op_array_integrity(dst);*/ dump(dst); return dst; @@ -1754,9 +1926,20 @@ /* {{{ apc_copy_function_for_execution */ zend_function* apc_copy_function_for_execution(zend_function* src) { - zend_function* dst = (zend_function*) emalloc(sizeof(src[0])); + zend_function* dst; + TSRMLS_FETCH(); + + /* TODO: the refcount is set high, so that this isn't free'd + by the destroy_zend_function. There is no real way around + it rather than just copying a shovelful of data in real mem. + Something I'd rather avoid */ + dst = (zend_function*) emalloc(sizeof(src[0])); memcpy(dst, src, sizeof(src[0])); dst->op_array.static_variables = my_copy_static_variables(&dst->op_array, apc_php_malloc, apc_php_free); +#ifdef ZEND_ENGINE_2 + my_fetch_global_vars(&dst->op_array TSRMLS_CC); + my_copy_default_args(&dst->op_array, &src->op_array); +#endif /*check_op_array_integrity(&dst->op_array);*/ return dst; } @@ -1776,6 +1959,12 @@ zend_class_entry* dst = (zend_class_entry*) emalloc(sizeof(src[0])); memcpy(dst, src, sizeof(src[0])); + /* + dst->name = apc_xstrdup(src->name, apc_php_malloc); + dst->refcount = 0; + */ + + #ifdef ZEND_ENGINE_2 /* These are slots to be populated later by ADD_INTERFACE insns */ dst->interfaces = apc_php_malloc(sizeof(zend_class_entry*) * @@ -1825,13 +2014,27 @@ 1, apc_php_malloc, apc_php_free); - dst->static_members = my_copy_hashtable(NULL, - src->static_members, + my_copy_hashtable(&dst->default_static_members, + &src->default_static_members, (ht_copy_fun_t) my_copy_zval_ptr, (ht_free_fun_t) my_free_zval_ptr, 1, apc_php_malloc, apc_php_free); + if(src->static_members != &(src->default_static_members)) + { + dst->static_members = my_copy_hashtable(NULL, + src->static_members, + (ht_copy_fun_t) my_copy_zval_ptr, + (ht_free_fun_t) my_free_zval_ptr, + 1, + apc_php_malloc, apc_php_free); + } + else + { + dst->static_members = &(dst->default_static_members); + } + #endif return dst; @@ -1870,6 +2073,8 @@ { SET_IF_SAME_NAME(__get); SET_IF_SAME_NAME(__set); + SET_IF_SAME_NAME(__unset); + SET_IF_SAME_NAME(__isset); SET_IF_SAME_NAME(__call); } zf->common.scope = dst; @@ -1950,12 +2155,16 @@ static int my_check_copy_static_member(Bucket* p, va_list args) { zend_class_entry* src = va_arg(args, zend_class_entry*); + HashTable * ht = va_arg(args, HashTable*); zend_class_entry* parent = src->parent; + HashTable * parent_ht = NULL; char * member_name; - char * class_name; + char * class_name = NULL; zend_property_info *parent_info = NULL; zend_property_info *child_info = NULL; + zval ** parent_prop = NULL; + zval ** child_prop = (zval**)(p->pData); if(!parent) { return 1; @@ -1983,6 +2192,24 @@ */ return 0; } + if(ht == &(src->default_static_members)) + { + parent_ht = &parent->default_static_members; + } + else + { + parent_ht = parent->static_members; + } + + if(zend_hash_quick_find(parent_ht, p->arKey, + p->nKeyLength, p->h, (void**)&parent_prop) == SUCCESS) + { + /* they point to the same zval */ + if(*parent_prop == *child_prop) + { + return 0; + } + } } return 1; http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_compile.h?r1=3.8&r2=3.8.2.1&diff_format=u Index: pecl/apc/apc_compile.h diff -u pecl/apc/apc_compile.h:3.8 pecl/apc/apc_compile.h:3.8.2.1 --- pecl/apc/apc_compile.h:3.8 Thu Jun 23 09:10:35 2005 +++ pecl/apc/apc_compile.h Sun Mar 12 04:16:00 2006 @@ -27,7 +27,7 @@ */ -/* $Id: apc_compile.h,v 3.8 2005/06/23 09:10:35 rasmus Exp $ */ +/* $Id: apc_compile.h,v 3.8.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #ifndef APC_COMPILE_H #define APC_COMPILE_H @@ -55,6 +55,8 @@ struct apc_class_t { char* name; /* the class name */ int name_len; /* length of name */ + char* mangled_name; /* the mangled internal name */ + int mangled_name_len; /* length of the mangled name */ int is_derived; /* true if this is a derived class */ char* parent_name; /* the parent class name */ zend_class_entry* class_entry; /* the zend class data structure */ @@ -87,7 +89,7 @@ * structures. */ -extern zend_op_array* apc_copy_op_array_for_execution(zend_op_array* src); +extern zend_op_array* apc_copy_op_array_for_execution(zend_op_array* src TSRMLS_DC); extern zend_function* apc_copy_function_for_execution(zend_function* src); extern zend_class_entry* apc_copy_class_entry_for_execution(zend_class_entry* src, int is_derived); http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_debug.c?r1=3.2.2.1&r2=3.2.2.2&diff_format=u Index: pecl/apc/apc_debug.c diff -u pecl/apc/apc_debug.c:3.2.2.1 pecl/apc/apc_debug.c:3.2.2.2 --- pecl/apc/apc_debug.c:3.2.2.1 Thu Dec 15 08:19:09 2005 +++ pecl/apc/apc_debug.c Sun Mar 12 04:16:00 2006 @@ -26,7 +26,7 @@ All other licensing and usage conditions are those of the PHP Group. */ -/* $Id: apc_debug.c,v 3.2.2.1 2005/12/15 08:19:09 rasmus Exp $ */ +/* $Id: apc_debug.c,v 3.2.2.2 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc.h" #include <stdio.h> #include "zend_compile.h" @@ -513,6 +513,7 @@ void dump(zend_op_array *op_array) { int i; + return; if(op_array->filename) { fprintf(stderr, "Ops for %s\n", op_array->filename); } http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_fcntl_win32.c?r1=3.3&r2=3.3.2.1&diff_format=u Index: pecl/apc/apc_fcntl_win32.c diff -u pecl/apc/apc_fcntl_win32.c:3.3 pecl/apc/apc_fcntl_win32.c:3.3.2.1 --- pecl/apc/apc_fcntl_win32.c:3.3 Fri Jul 29 20:48:59 2005 +++ pecl/apc/apc_fcntl_win32.c Sun Mar 12 04:16:00 2006 @@ -25,7 +25,7 @@ */ -/* $Id: apc_fcntl_win32.c,v 3.3 2005/07/29 20:48:59 fmk Exp $ */ +/* $Id: apc_fcntl_win32.c,v 3.3.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc_fcntl.h" #include "apc.h" @@ -38,11 +38,18 @@ int apc_fcntl_create(const char* pathname) { - char *lock_file; + char *lock_file = emalloc(MAXPATHLEN); HANDLE fd; + DWORD tmplen; static int i=0; - spprintf(&lock_file, 0, "/tmp/apc.lock.%d", i++); + tmplen = GetTempPath(MAXPATHLEN, lock_file); + if (!tmplen) { + efree(lock_file); + return -1; + } + + snprintf(lock_file + tmplen, MAXPATHLEN - tmplen - 1, "apc.lock.%d", i++); fd = CreateFile(lock_file, GENERIC_READ | GENERIC_WRITE, @@ -91,7 +98,11 @@ OVERLAPPED offset = {0, 0, 0, 0, NULL}; if (!UnlockFileEx((HANDLE)fd, 0, 1, 0, &offset)) { - apc_eprint("apc_fcntl_unlock failed errno:%d", GetLastError()); + DWORD error_code = GetLastError(); + /* Ignore already unlocked error */ + if (error_code != ERROR_NOT_LOCKED) { + apc_eprint("apc_fcntl_unlock failed errno:%d", error_code); + } } } http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_globals.h?r1=3.30.2.1&r2=3.30.2.2&diff_format=u Index: pecl/apc/apc_globals.h diff -u pecl/apc/apc_globals.h:3.30.2.1 pecl/apc/apc_globals.h:3.30.2.2 --- pecl/apc/apc_globals.h:3.30.2.1 Thu Dec 15 08:19:09 2005 +++ pecl/apc/apc_globals.h Sun Mar 12 04:16:00 2006 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | APC | +----------------------------------------------------------------------+ - | Copyright (c) 2005 The PHP Group | + | Copyright (c) 2006 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -29,12 +29,12 @@ */ -/* $Id: apc_globals.h,v 3.30.2.1 2005/12/15 08:19:09 rasmus Exp $ */ +/* $Id: apc_globals.h,v 3.30.2.2 2006/03/12 04:16:00 gopalv Exp $ */ #ifndef APC_GLOBALS_H #define APC_GLOBALS_H -#define APC_VERSION "3.0.9-dev" +#define APC_VERSION "3.0.9" #include "apc_cache.h" #include "apc_stack.h" @@ -42,32 +42,34 @@ ZEND_BEGIN_MODULE_GLOBALS(apc) /* configuration parameters */ - int enabled; /* if true, apc is enabled (defaults to true) */ - int shm_segments; /* number of shared memory segments to use */ - int shm_size; /* size of each shared memory segment (in MB) */ - int optimization; /* optimizer level (higher = more aggressive) */ - int num_files_hint; /* parameter to apc_cache_create */ - int user_entries_hint; - int gc_ttl; /* parameter to apc_cache_create */ - int ttl; /* parameter to apc_cache_create */ - int user_ttl; + zend_bool enabled; /* if true, apc is enabled (defaults to true) */ + long shm_segments; /* number of shared memory segments to use */ + long shm_size; /* size of each shared memory segment (in MB) */ + long optimization; /* optimizer level (higher = more aggressive) */ + long num_files_hint; /* parameter to apc_cache_create */ + long user_entries_hint; + long gc_ttl; /* parameter to apc_cache_create */ + long ttl; /* parameter to apc_cache_create */ + long user_ttl; #if APC_MMAP char *mmap_file_mask; /* mktemp-style file-mask to pass to mmap */ #endif char** filters; /* array of regex filters that prevent caching */ /* module variables */ - int initialized; /* true if module was initialized */ - apc_stack_t* cache_stack; /* the stack of cached executable code */ - int cache_by_default; /* true if files should be cached unless filtered out */ - /* false if files should only be cached if filtered in */ - int slam_defense; /* Probability of a process not caching an uncached file */ - size_t* mem_size_ptr; /* size of blocks allocated to file being cached (NULL outside my_compile_file) */ - int file_update_protection; /* Age in seconds before a file is eligible to be cached - 0 to disable */ - int enable_cli; /* Flag to override turning APC off for CLI */ - long max_file_size; /* Maximum size of file, in bytes that APC will be allowed to cache */ + zend_bool initialized; /* true if module was initialized */ + apc_stack_t* cache_stack; /* the stack of cached executable code */ + zend_bool cache_by_default; /* true if files should be cached unless filtered out */ + /* false if files should only be cached if filtered in */ + zend_bool slam_defense; /* Probability of a process not caching an uncached file */ + size_t* mem_size_ptr; /* size of blocks allocated to file being cached (NULL outside my_compile_file) */ + long file_update_protection; /* Age in seconds before a file is eligible to be cached - 0 to disable */ + zend_bool enable_cli; /* Flag to override turning APC off for CLI */ + long max_file_size; /* Maximum size of file, in bytes that APC will be allowed to cache */ + long slam_rand; /* A place to store the slam rand value for the request */ int dynamic_error; /* Error on runtime dynamic inheritance */ HashTable delayed_inheritance_hash; + zend_bool fpstat; /* true if fullpath includes should be stat'ed */ ZEND_END_MODULE_GLOBALS(apc) /* (the following declaration is defined in php_apc.c) */ @@ -82,7 +84,7 @@ /* True globals */ extern apc_cache_t* apc_cache; /* the global compiler cache */ extern apc_cache_t* apc_user_cache; /* the global user content cache */ -extern void* apc_compiled_filters; /* compiled filters */ +extern void* apc_compiled_filters; /* compiled filters */ #endif http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_main.c?r1=3.63.2.1&r2=3.63.2.2&diff_format=u Index: pecl/apc/apc_main.c diff -u pecl/apc/apc_main.c:3.63.2.1 pecl/apc/apc_main.c:3.63.2.2 --- pecl/apc/apc_main.c:3.63.2.1 Thu Dec 15 08:19:09 2005 +++ pecl/apc/apc_main.c Sun Mar 12 04:16:00 2006 @@ -28,7 +28,7 @@ */ -/* $Id: apc_main.c,v 3.63.2.1 2005/12/15 08:19:09 rasmus Exp $ */ +/* $Id: apc_main.c,v 3.63.2.2 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc_php.h" #include "apc_main.h" @@ -54,7 +54,7 @@ /* pointer to the original Zend engine compile_file function */ typedef zend_op_array* (zend_compile_t)(zend_file_handle*, int TSRMLS_DC); static zend_compile_t *old_compile_file; -static int recursive_inheritance(zend_class_entry *class_entry); +static int recursive_inheritance(const apc_class_t *cl); /* }}} */ @@ -80,7 +80,7 @@ NULL); if (status == FAILURE) { - zend_error(E_ERROR, "Cannot redeclare %s()", fn.name); + /* zend_error(E_ERROR, "Cannot redeclare %s()", fn.name); */ } return status; @@ -89,7 +89,7 @@ typedef struct apc_hash_link_t apc_hash_link_t; struct apc_hash_link_t { - zend_class_entry *ce; + apc_class_t cl; apc_hash_link_t *next; }; @@ -122,10 +122,14 @@ { zend_class_entry *class_entry; zend_class_entry *parent; - apc_hash_link_t *he; int status; class_entry = apc_copy_class_entry_for_execution(cl.class_entry, cl.is_derived); + + /* remember, this was passed by value. + cached shm version isn't modified */ + cl.class_entry = class_entry; + zend_error(E_WARNING, "%d classes in the class_table", zend_hash_num_elements(EG(class_table))); if(cl.parent_name != NULL) { @@ -142,29 +146,32 @@ #endif zend_do_inheritance(class_entry, parent TSRMLS_CC); zend_error(E_WARNING, "Inheriting into %s from parent %s", class_entry->name, parent->name); - status = recursive_inheritance(class_entry); + status = recursive_inheritance(&cl); } else { + apc_hash_link_t *hl = NULL; + int added = 0; + char *lower_parent = NULL; if(APCG(dynamic_error)) { zend_error(E_WARNING, "Dynamic inheritance detected on %s extending %s", class_entry->name, cl.parent_name); } - apc_hash_link_t *hl = apc_php_malloc(sizeof(apc_hash_link_t *)); - int added = 0; - char *lower_parent = estrndup(cl.parent_name, parent_len); + hl = apc_php_malloc(sizeof(apc_hash_link_t)); + lower_parent = estrndup(cl.parent_name, parent_len); zend_str_tolower(lower_parent, parent_len); - hl->ce = class_entry; + hl->cl = cl; + hl->cl.class_entry = class_entry; hl->next = NULL; if(APCG(delayed_inheritance_hash).nNumOfElements) { - apc_hash_link_t **ehl; + apc_hash_link_t *ehl; status = zend_hash_find(&APCG(delayed_inheritance_hash), lower_parent, parent_len+1, (void **)&ehl); if(status == SUCCESS) { /* It's already in the hash, so add the class_entry to the linked list */ - while((*ehl)->next) *ehl=(*ehl)->next; - (*ehl)->next = hl; + while(ehl->next) ehl=ehl->next; + ehl->next = hl; added = 1; } } if(!added) { - zend_hash_add(&APCG(delayed_inheritance_hash), lower_parent, parent_len+1, (void *)&hl, sizeof(apc_hash_link_t *), NULL); + zend_hash_add(&APCG(delayed_inheritance_hash), lower_parent, parent_len+1, (void *)hl, sizeof(apc_hash_link_t), NULL); } class_entry->parent = NULL; efree(lower_parent); @@ -172,7 +179,7 @@ } } else { status = SUCCESS; - status = recursive_inheritance(class_entry); + status = recursive_inheritance(&cl); } zend_error(E_WARNING, "now %d classes in the class_table", zend_hash_num_elements(EG(class_table))); @@ -193,8 +200,11 @@ * the hash entry from the delayed inheritance list and finally we add the class * to the class table. */ -static int recursive_inheritance(zend_class_entry *class_entry) { - apc_hash_link_t **ehl; +static int recursive_inheritance(const apc_class_t *cl) { + zend_class_entry *class_entry = cl->class_entry; + const char * mangled_name = cl->mangled_name; + int mangled_name_len = cl->mangled_name_len; + apc_hash_link_t *ehl; zend_class_entry **allocated_ce; int status; char *lower_cen = estrndup(class_entry->name, class_entry->name_length); @@ -203,15 +213,15 @@ zend_error(E_WARNING, "Recursive inheritance called for %s", class_entry->name); if(status == SUCCESS) { do { - zend_do_inheritance((*ehl)->ce, class_entry TSRMLS_CC); - zend_error(E_WARNING, "Inheriting into %s from parent %s", (*ehl)->ce->name, class_entry->name); - zend_error(E_WARNING, "Recursing for %s", (*ehl)->ce->name); - status = recursive_inheritance((*ehl)->ce); + zend_do_inheritance(ehl->cl.class_entry, class_entry TSRMLS_CC); + zend_error(E_WARNING, "Inheriting into %s from parent %s", ehl->cl.class_entry->name, class_entry->name); + zend_error(E_WARNING, "Recursing for %s", ehl->cl.class_entry->name); + status = recursive_inheritance(&ehl->cl); if(status == FAILURE) { efree(lower_cen); return status; } - } while(*ehl = (*ehl)->next); + } while((ehl = ehl->next) != NULL); zend_error(E_WARNING, "Removing %s from hash (%d)", lower_cen, APCG(delayed_inheritance_hash).nNumOfElements); zend_hash_del(&APCG(delayed_inheritance_hash), lower_cen, class_entry->name_length+1); zend_error(E_WARNING, "%d left", APCG(delayed_inheritance_hash).nNumOfElements); @@ -225,7 +235,17 @@ return FAILURE; } *allocated_ce = class_entry; - status = zend_hash_add(EG(class_table), lower_cen, class_entry->name_length+1, allocated_ce, sizeof(zend_class_entry*), NULL); + if(mangled_name) + { + efree(lower_cen); + lower_cen = apc_xmemcpy(mangled_name, mangled_name_len, apc_php_malloc); + assert(lower_cen != NULL); + status = zend_hash_add(EG(class_table), lower_cen, mangled_name_len, allocated_ce, sizeof(zend_class_entry*), NULL); + } + else + { + status = zend_hash_add(EG(class_table), lower_cen, class_entry->name_length+1, allocated_ce, sizeof(zend_class_entry*), NULL); + } #else status = zend_hash_add(EG(class_table), lower_cen, class_entry->name_length+1, class_entry, sizeof(zend_class_entry), NULL); #endif @@ -241,6 +261,7 @@ /* }}} */ /* {{{ old_install_class */ +#if 0 static int old_install_class(apc_class_t cl TSRMLS_DC) { zend_class_entry* class_entry = cl.class_entry; @@ -347,6 +368,7 @@ } return status; } +#endif /* #if 0 */ /* }}} */ /* {{{ cached_compile */ @@ -370,7 +392,7 @@ } } - return apc_copy_op_array_for_execution(cache_entry->data.file.op_array); + return apc_copy_op_array_for_execution(cache_entry->data.file.op_array TSRMLS_CC); } /* }}} */ @@ -390,7 +412,7 @@ char *path; size_t mem_size; - if (!APCG(enabled)) { + if (!APCG(enabled) || apc_cache_busy(apc_cache)) { return old_compile_file(h, type TSRMLS_CC); } @@ -414,6 +436,10 @@ t = sapi_get_request_time(TSRMLS_C); #endif +#ifdef __DEBUG_APC__ + fprintf(stderr,"1. h->opened_path=[%s] h->filename=[%s]\n", h->opened_path?h->opened_path:"null",h->filename); +#endif + /* try to create a cache key; if we fail, give up on caching */ if (!apc_cache_make_file_key(&key, h->filename, PG(include_path), t TSRMLS_CC)) { return old_compile_file(h, type TSRMLS_CC); @@ -451,11 +477,13 @@ * For example if apc.slam_defense is set to 66 then 2/3 of the attempts * to cache an uncached file will be ignored. */ - if(APCG(slam_rand)==-1) { - APCG(slam_rand) = (int)(100.0*rand()/(RAND_MAX+1.0)); - } - if(APCG(slam_defense) && APCG(slam_rand) < APCG(slam_defense)) { - return op_array; + if(APCG(slam_defense)) { + if(APCG(slam_rand)==-1) { + APCG(slam_rand) = (int)(100.0*rand()/(RAND_MAX+1.0)); + } + if(APCG(slam_rand) < APCG(slam_defense)) { + return op_array; + } } HANDLE_BLOCK_INTERRUPTIONS(); @@ -490,6 +518,10 @@ path = h->opened_path; if(!path) path=h->filename; +#ifdef __DEBUG_APC__ + fprintf(stderr,"2. h->opened_path=[%s] h->filename=[%s]\n", h->opened_path?h->opened_path:"null",h->filename); +#endif + if(!(cache_entry = apc_cache_make_file_entry(path, alloc_op_array, alloc_functions, alloc_classes))) { apc_free_op_array(alloc_op_array, apc_sma_free); apc_free_functions(alloc_functions, apc_sma_free); @@ -588,6 +620,11 @@ if(APCG(delayed_inheritance_hash).nNumOfElements) { zend_hash_clean(&APCG(delayed_inheritance_hash)); } + /* Safety net */ +#if 0 + apc_sma_unlock(); + apc_cache_unlock(apc_cache); +#endif } /* }}} */ http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_sma.c?r1=1.29&r2=1.29.2.1&diff_format=u Index: pecl/apc/apc_sma.c diff -u pecl/apc/apc_sma.c:1.29 pecl/apc/apc_sma.c:1.29.2.1 --- pecl/apc/apc_sma.c:1.29 Fri Jul 29 20:48:39 2005 +++ pecl/apc/apc_sma.c Sun Mar 12 04:16:00 2006 @@ -26,7 +26,7 @@ */ -/* $Id: apc_sma.c,v 1.29 2005/07/29 20:48:39 fmk Exp $ */ +/* $Id: apc_sma.c,v 1.29.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #include "apc_sma.h" #include "apc.h" @@ -45,13 +45,11 @@ #define UNLOCK(c) { apc_lck_unlock(c); HANDLE_UNBLOCK_INTERRUPTIONS(); } /* }}} */ -enum { POWER_OF_TWO_BLOCKSIZE=0 }; /* force allocated blocks to 2^n? */ - enum { DEFAULT_NUMSEG=1, DEFAULT_SEGSIZE=30*1024*1024 }; static int sma_initialized = 0; /* true if the sma has been initialized */ -static int sma_numseg; /* number of shm segments to allow */ -static int sma_segsize; /* size of each shm segment */ +static unsigned int sma_numseg; /* number of shm segments to allow */ +static size_t sma_segsize; /* size of each shm segment */ static int* sma_segments; /* array of shm segment ids */ static void** sma_shmaddrs; /* array of shm segment addresses */ static int sma_lastseg = 0; /* index of MRU segment */ @@ -59,14 +57,18 @@ typedef struct header_t header_t; struct header_t { - int segsize; /* size of entire segment */ - int avail; /* bytes available (not necessarily contiguous) */ + size_t segsize; /* size of entire segment */ + size_t avail; /* bytes available (not necessarily contiguous) */ + size_t nfoffset; /* start next fit search from this offset */ +#if ALLOC_DISTRIBUTION + size_t adist[30]; +#endif }; typedef struct block_t block_t; struct block_t { - int size; /* size of this block */ - int next; /* offset in segment of next free block */ + size_t size; /* size of this block */ + size_t next; /* offset in segment of next free block */ }; /* The macros BLOCKAT and OFFSET are used for convenience throughout this @@ -74,7 +76,7 @@ * beginning of the shared memory segment in question. */ #define BLOCKAT(offset) ((block_t*)((char *)shmaddr + offset)) -#define OFFSET(block) ((int)(((char*)block) - (char*)shmaddr)) +#define OFFSET(block) ((size_t)(((char*)block) - (char*)shmaddr)) #ifdef max #undef max @@ -90,31 +92,17 @@ /* }}} */ /* {{{ sma_allocate: tries to allocate size bytes in a segment */ -static int sma_allocate(void* shmaddr, int size) +static int sma_allocate(void* shmaddr, size_t size) { header_t* header; /* header of shared memory segment */ block_t* prv; /* block prior to working block */ block_t* cur; /* working block in list */ - block_t* prvbestfit; /* block before best fit */ - int realsize; /* actual size of block needed, including header */ - int minsize; /* for finding best fit */ + block_t* prvnextfit; /* block before next fit */ + size_t realsize; /* actual size of block needed, including header */ + size_t last_offset; /* save the last search offset */ + int wrapped=0; - /* Realsize must be aligned to a word boundary on some architectures. */ realsize = alignword(max(size + alignword(sizeof(int)), sizeof(block_t))); - - /* - * Set realsize to the smallest power of 2 greater than or equal to - * realsize. This increases the likelihood that neighboring blocks can be - * coalesced, reducing memory fragmentation. - */ - if (POWER_OF_TWO_BLOCKSIZE) { - int p = 1; - - while (p < realsize) { - p <<= 1; - } - realsize = p; - } /* * First, insure that the segment contains at least realsize free bytes, @@ -125,55 +113,67 @@ return -1; } - prvbestfit = 0; /* initially null (no fit) */ - minsize = INT_MAX; /* used to find best fit */ + prvnextfit = 0; /* initially null (no fit) */ + last_offset = 0; - prv = BLOCKAT(sizeof(header_t)); - while (prv->next != 0) { + /* If we have a next fit offset, start searching from there */ + if(header->nfoffset) { + prv = BLOCKAT(header->nfoffset); + } else { + prv = BLOCKAT(sizeof(header_t)); + } + while (prv->next != header->nfoffset) { cur = BLOCKAT(prv->next); - if (cur->size == realsize) { - /* found a perfect fit, stop searching */ - prvbestfit = prv; + /* If it fits perfectly or it fits after a split, stop searching */ + if (cur->size == realsize || (cur->size > (sizeof(block_t) + realsize))) { + prvnextfit = prv; break; } - else if (cur->size > (sizeof(block_t) + realsize) && - cur->size < minsize) - { - /* cur is acceptable and is the smallest so far */ - prvbestfit = prv; - minsize = cur->size; - } + last_offset = prv->next; prv = cur; + if(wrapped && (prv->next >= header->nfoffset)) break; + + /* Check to see if we need to wrap around and search from the top */ + if(header->nfoffset && prv->next == 0) { + prv = BLOCKAT(sizeof(header_t)); + last_offset = 0; + wrapped = 1; + } } - if (prvbestfit == 0) { + if (prvnextfit == 0) { + header->nfoffset = 0; return -1; } - prv = prvbestfit; + prv = prvnextfit; cur = BLOCKAT(prv->next); /* update the block header */ header->avail -= realsize; +#if ALLOC_DISTRIBUTION + header->adist[(int)(log(size)/log(2))]++; +#endif if (cur->size == realsize) { /* cur is a perfect fit for realsize; just unlink it */ prv->next = cur->next; } else { - block_t* nxt; /* the new block (chopped part of cur) */ - int nxtoffset; /* offset of the block currently after cur */ - int oldsize; /* size of cur before split */ + block_t* nxt; /* the new block (chopped part of cur) */ + size_t nxtoffset; /* offset of the block currently after cur */ + size_t oldsize; /* size of cur before split */ - /* bestfit is too big; split it into two smaller blocks */ + /* nextfit is too big; split it into two smaller blocks */ nxtoffset = cur->next; oldsize = cur->size; - prv->next += realsize; - cur->size = realsize; + prv->next += realsize; /* skip over newly allocated block */ + cur->size = realsize; /* Set the size of this new block */ nxt = BLOCKAT(prv->next); - nxt->next = nxtoffset; - nxt->size = oldsize - realsize; + nxt->next = nxtoffset; /* Re-link the shortened block */ + nxt->size = oldsize - realsize; /* and fix the size */ } + header->nfoffset = last_offset; return OFFSET(cur) + alignword(sizeof(int)); } @@ -186,9 +186,9 @@ block_t* cur; /* the new block to insert */ block_t* prv; /* the block before cur */ block_t* nxt; /* the block after cur */ - int size; /* size of deallocated block */ + size_t size; /* size of deallocated block */ - offset -= alignword(sizeof(int)); + offset -= alignword(sizeof(size_t)); assert(offset >= 0); /* find position of new block in free list */ @@ -220,6 +220,7 @@ cur->size += nxt->size; cur->next = nxt->next; } + header->nfoffset = 0; /* Reset the next fit search marker */ return size; } @@ -277,11 +278,16 @@ header->segsize = sma_segsize; header->avail = sma_segsize - sizeof(header_t) - sizeof(block_t) - alignword(sizeof(int)); - + header->nfoffset = 0; +#if ALLOC_DISTRIBUTION + { + int j; + for(j=0; j<30; j++) header->adist[j] = 0; + } +#endif block = BLOCKAT(sizeof(header_t)); block->size = 0; block->next = sizeof(header_t) + sizeof(block_t); - block = BLOCKAT(block->next); block->size = header->avail; block->next = 0; @@ -305,6 +311,8 @@ } apc_lck_destroy(sma_lock); sma_initialized = 0; + apc_efree(sma_segments); + apc_efree(sma_shmaddrs); } /* }}} */ @@ -373,7 +381,7 @@ void apc_sma_free(void* p) { int i; - TSRMLS_FETCH(); + TSRMLS_FETCH(); if (p == NULL) { return; @@ -383,7 +391,7 @@ LOCK(sma_lock); for (i = 0; i < sma_numseg; i++) { - unsigned int d_size = (unsigned int)((char *)p - (char *)(sma_shmaddrs[i])); + size_t d_size = (size_t)((char *)p - (char *)(sma_shmaddrs[i])); if (p >= sma_shmaddrs[i] && d_size < sma_segsize) { sma_deallocate(sma_shmaddrs[i], d_size); if (APCG(mem_size_ptr) != NULL) { *(APCG(mem_size_ptr)) -= d_size; } @@ -410,7 +418,7 @@ info = (apc_sma_info_t*) apc_emalloc(sizeof(apc_sma_info_t)); info->num_seg = sma_numseg; - info->seg_size = sma_segsize; + info->seg_size = sma_segsize - sizeof(header_t) - sizeof(block_t) - alignword(sizeof(int)); info->list = apc_emalloc(info->num_seg * sizeof(apc_sma_link_t*)); for (i = 0; i < sma_numseg; i++) { @@ -477,6 +485,19 @@ } /* }}} */ +#if ALLOC_DISTRIBUTION +size_t *apc_sma_get_alloc_distribution(void) { + header_t* header = (header_t*) sma_shmaddrs[0]; + return header->adist; +} +#endif +/* {{{ apc_sma_unlock */ +void apc_sma_unlock() +{ + UNLOCK(sma_lock); +} +/* }}} */ + #if 0 /* {{{ apc_sma_check_integrity */ void apc_sma_check_integrity() http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_sma.h?r1=1.11&r2=1.11.2.1&diff_format=u Index: pecl/apc/apc_sma.h diff -u pecl/apc/apc_sma.h:1.11 pecl/apc/apc_sma.h:1.11.2.1 --- pecl/apc/apc_sma.h:1.11 Thu Jun 23 09:10:36 2005 +++ pecl/apc/apc_sma.h Sun Mar 12 04:16:00 2006 @@ -25,11 +25,13 @@ */ -/* $Id: apc_sma.h,v 1.11 2005/06/23 09:10:36 rasmus Exp $ */ +/* $Id: apc_sma.h,v 1.11.2.1 2006/03/12 04:16:00 gopalv Exp $ */ #ifndef APC_SMA_H #define APC_SMA_H +#define ALLOC_DISTRIBUTION 0 + #include "apc.h" /* Simple shared memory allocator */ @@ -40,6 +42,10 @@ extern void* apc_sma_realloc(void* p, size_t size); extern char* apc_sma_strdup(const char *s); extern void apc_sma_free(void* p); +extern void apc_sma_unlock(); +#if ALLOC_DISTRIBUTION +extern size_t *apc_sma_get_alloc_distribution(); +#endif /* {{{ struct definition: apc_sma_link_t */ typedef struct apc_sma_link_t apc_sma_link_t; http://cvs.php.net/viewcvs.cgi/pecl/apc/config.m4?r1=3.12&r2=3.12.2.1&diff_format=u Index: pecl/apc/config.m4 diff -u pecl/apc/config.m4:3.12 pecl/apc/config.m4:3.12.2.1 --- pecl/apc/config.m4:3.12 Sat Nov 12 15:12:40 2005 +++ pecl/apc/config.m4 Sun Mar 12 04:16:00 2006 @@ -1,7 +1,8 @@ dnl -dnl $Id: config.m4,v 3.12 2005/11/12 15:12:40 rasmus Exp $ +dnl $Id: config.m4,v 3.12.2.1 2006/03/12 04:16:00 gopalv Exp $ dnl +AC_MSG_CHECKING(whether apc needs to get compiler flags from apxs) AC_ARG_WITH(apxs, [ --with-apxs[=FILE] Get compiler flags from apxs -q. Provide the pathname to the Apache apxs tool; defaults to "apxs".],[ http://cvs.php.net/viewcvs.cgi/pecl/apc/package.xml?r1=1.36&r2=1.36.2.1&diff_format=u Index: pecl/apc/package.xml diff -u pecl/apc/package.xml:1.36 pecl/apc/package.xml:1.36.2.1 --- pecl/apc/package.xml:1.36 Wed Nov 16 15:48:08 2005 +++ pecl/apc/package.xml Sun Mar 12 04:16:00 2006 @@ -1,50 +1,49 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> -<!DOCTYPE package SYSTEM "../pear/package.dtd"> -<package> - <dep type="php" rel="ge" version="4.3.0" optional="no"/> +<?xml version="1.0" encoding="UTF-8" ?> +<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst +ance" packagerversion="1.4.7" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.p +hp.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>APC</name> + <channel>pecl.php.net</channel> <summary>Alternative PHP Cache</summary> - <maintainers> - <maintainer> - <user>dcowgill</user> - <name>Daniel Cowgill</name> - <email>dan@mail.communityconnect.com</email> - <role>lead</role> - </maintainer> - <maintainer> - <user>gschlossnagle</user> - <name>George Schlossnagle</name> - <email>george@omniti.com</email> - <role>lead</role> - </maintainer> - <maintainer> - <user>rasmus</user> - <name>Rasmus Lerdorf</name> - <email>rasmus@php.net</email> - <role>lead</role> - </maintainer> - </maintainers> - <description> - APC is the Alternative PHP Cache. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code. - </description> - <license>PHP</license> - <release> - <state>stable</state> - <version>3.0.9</version> - <date>2005-08-??</date> - <notes> - </notes> - </release> - <configureoptions> - <configureoption name="enable-apc-mmap" default="yes" prompt="Use mmap instead of shmget (usually a good idea)"/> - <configureoption name="with-apxs" default="yes" prompt="Use apxs to set compile flags (if using APC with Apache)?"/> - </configureoptions> - <filelist> + <description>APC is a free, open, and robust framework for caching and optimizing PHP intermediate code.</description> + <lead> + <name>Daniel Cowgill</name> + <user>dcowgill</user> + <email>dan@mail.communityconnect.com</email> + <active>no</active> + </lead> + <lead> + <name>George Schlossnagle</name> + <user>gschlossnagle</user> + <email>george@omniti.com</email> + <active>no</active> + </lead> + <lead> + <name>Rasmus Lerdorf</name> + <user>rasmus</user> + <email>rasmus@php.net</email> + <active>yes</active> + </lead> + + <date>2006-03-??</date> + <version><release>3.0.10</release><api>3.0.0</api></version> + <stability><release>stable</release><api>stable</api></stability> + <license uri="http://www.php.net/license">PHP License</license> + <notes> + Add apc.stat ini flag which defaults to 1. If set to 0, the main script and any fullpath + includes will not be stat'ed for any changes. You will have to restart the server if you + change anything. This mode increases performance quite a bit, especially if you have a + lot of includes. + </notes> + + <contents> + <dir name="/"> <file role="doc" name="CHANGELOG" /> <file role="doc" name="INSTALL" /> <file role="doc" name="LICENSE" /> <file role="doc" name="NOTICE" /> <file role="doc" name="TODO" /> + <file role="doc" name="TECHNOTES.txt" /> <file role="src" name="apc.c" /> <file role="src" name="apc.dsp" /> <file role="src" name="apc.h" /> @@ -81,90 +80,123 @@ <file role="src" name="php_apc.h" /> <file role="src" name="apc_fcntl_win32.c" /> <file role="php" name="apc.php" /> - </filelist> - <changelog> - <release> - <state>stable</state> - <version>2.0</version> - <date>2003-07-01</date> - <notes> + <dir name="tests"> + <file role="test" name="apc_001.phpt" /> + <file role="test" name="apc_002.phpt" /> + <file role="test" name="apc_003.phpt" /> + <file role="test" name="skipif.inc" /> + </dir> + </dir> + </contents> + + <dependencies> + <required> + <php> + <min>4.3.0</min> + <exclude>5.0.0</exclude> + <exclude>5.0.1</exclude> + <exclude>5.0.2</exclude> + <exclude>5.0.3</exclude> + <exclude>5.0.4</exclude> + <exclude>5.0.5</exclude> + </php> + <pearinstaller> + <min>1.4.0</min> + </pearinstaller> + </required> + + </dependencies> + + <providesextension>apc</providesextension> + + <extsrcrelease> + <configureoption name="enable-apc-mmap" default="yes" prompt="Use mmap instead of shmget (usually a good idea)"/> + <configureoption name="with-apxs" default="yes" prompt="Use apxs to set compile flags (if using APC with Apache)?"/> + </extsrcrelease> + + <changelog> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>2.0.0</release><api>2.0.0</api></version> + <date>2003-07-01</date> + <notes> Complete rework. + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>2.0.1</release><api>2.0.0</api></version> + <date>2003-07-01</date> + <notes> +Win32 support added. </notes> - </release> - <release> - <state>stable</state> - <version>2.0.1</version> - <date>2003-07-01</date> - <notes> - Win32 support added. - </notes> - </release> - <release> - <state>stable</state> - <version>2.0.2</version> - <date>2004-03-12</date> - <notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>2.0.2</release><api>2.0.0</api></version> + <date>2004-03-12</date> + <notes> Fixed non-existant class bug. - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.0</version> - <date>2005-07-05</date> - <notes> - PHP-5.1 Support and numerous fixes - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.1</version> - <date>2005-07-05</date> - <notes> - PHP4 build fix - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.2</version> - <date>2005-07-05</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.0</release><api>3.0.0</api></version> + <date>2005-07-05</date> + <notes> +PHP-5.1 Support and numerous fixes + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.1</release><api>3.0.0</api></version> + <date>2005-07-05</date> + <notes> +PHP4 build fix + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.2</release><api>3.0.0</api></version> + <date>2005-07-05</date> + <notes> Default to mmap and add a better error message for shmget failures - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.3</version> - <date>2005-07-07</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.3</release><api>3.0.0</api></version> + <date>2005-07-07</date> + <notes> Fix compile problem against PHP 5.0.x - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.4</version> - <date>2005-07-18</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.4</release><api>3.0.0</api></version> + <date>2005-07-18</date> + <notes> Add win32 support from Edin. Add --with-apxs switch to work around problem when loading APC into Apache binary compiled with LFS switches A couple of other minor fixes. - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.5</version> - <date>2005-07-27</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.5</release><api>3.0.0</api></version> + <date>2005-07-27</date> + <notes> Make it easier for sapis that only populate file_handle->filename to use APC. (Rasmus) Support extensions such as bcompiler that need to hook into compile_file. (Val) Ralf Becker's apcgui code has now become the default apc.php status page. (Ralf, Rasmus, Ilia) Segfault in cache cleanup code (Ilia, Rasmus) - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.6</version> - <date>2005-07-30</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.6</release><api>3.0.0</api></version> + <date>2005-07-30</date> + <notes> Added apc.php to package.xml file. Track per-entry memory usage. (Val) Various apc.php fixes and enhancements. (Ralf, Ilia, Rasmus) @@ -172,13 +204,13 @@ Shared read-locks where possible. (Rasmus) Added file_update_protection configuration parameter. (Rasmus) Windows ZTS fixes (Frank) - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.7</version> - <date>2005-08-16</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.7</release><api>3.0.0</api></version> + <date>2005-08-16</date> + <notes> Fix to apc.php to show final segment in frag chart. (Ilia) A couple of win32 fixes. (Frank) Add apc.enable_cli ini directive. (Rasmus) @@ -187,26 +219,42 @@ Simplify user cache handling by removing the user_cache_stack (Rasmus) Fix apc_fetch() memory corruption (Andrei,Rasmus) Added apc.max_file_size INI setting that allows exclusion of large files from being cached. Default file size limit, 1 megabyte. (Ilia) - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.8</version> - <date>2005-08-24</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.8</release><api>3.0.0</api></version> + <date>2005-08-24</date> + <notes> Fix invalid free in globals destructor introduced in 3.0.7 (Rasmus) Cache corruption fix in cache-full cleanup code (Gopal) - </notes> - </release> - <release> - <state>stable</state> - <version>3.0.9</version> - <date>2005-??-??</date> - <notes> + </notes> + </release> + <release> + <stability><release>stable</release><api>stable</api></stability> + <version><release>3.0.9</release><api>3.0.0</api></version> + <date>2006-03-04</date> + <notes> +Eliminate rand() call when slam_defense is not set (Rasmus) +Fix for __isset problem (Gopal) +Rewrite allocator from a "best fit" to a "next fit" algorithm (Rasmus) +Added a Cache Full counter so we have an idea how many times the segment has filled up causing an expunge (Rasmus) +Report back the correct number of available bytes in the segment instead of the allocated bytes. (Rasmus) +Add cache busy flag which is set when an expunge is underway (Rasmus) +Add automatic serialization of objects in apc_store() (Marcus) +64-bit .ini flag fix (Rasmus) +Static members fix (Gopal) +sma_cleanup() mem leak fix (Rasmus) +Fix for http://pecl.php.net/bugs/5311 (Rasmus) +Fix autoglobals JIT bug (Gopal) +Fix instance bug (Gopal) +Add a lock cleanup safety net to request shutdown (Rasmus) +Fix apc.slam_defense edge-case bug (Rasmus) +User entry memory usage tracking support (Ilia) Allow keys used in apc_store/apc_fetch/apc_delete to be binary safe and prevent conflicts between keys that are found at the start of other keys. (Ilia) - </notes> - </release> - </changelog> + </notes> + </release> + </changelog> </package> <!-- vim:et:ts=1:sw=1 http://cvs.php.net/viewcvs.cgi/pecl/apc/php_apc.c?r1=3.74.2.1&r2=3.74.2.2&diff_format=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.74.2.1 pecl/apc/php_apc.c:3.74.2.2 --- pecl/apc/php_apc.c:3.74.2.1 Thu Dec 15 08:19:09 2005 +++ pecl/apc/php_apc.c Sun Mar 12 04:16:00 2006 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | APC | +----------------------------------------------------------------------+ - | Copyright (c) 2005 The PHP Group | + | Copyright (c) 2006 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -26,7 +26,7 @@ */ -/* $Id: php_apc.c,v 3.74.2.1 2005/12/15 08:19:09 rasmus Exp $ */ +/* $Id: php_apc.c,v 3.74.2.2 2006/03/12 04:16:00 gopalv Exp $ */ #include "php_apc.h" #include "apc_zend.h" @@ -81,6 +81,7 @@ apc_globals->mem_size_ptr = NULL; /* zend_hash_init(&(apc_globals->delayed_inheritance_hash), 0, NULL, (void (*)(void *)) php_apc_hash_entry_destructor, 1); */ zend_hash_init(&(apc_globals->delayed_inheritance_hash), 0, NULL, NULL, 1); + apc_globals->fpstat = 1; } static void php_apc_shutdown_globals(zend_apc_globals* apc_globals TSRMLS_DC) @@ -141,24 +142,25 @@ #endif PHP_INI_BEGIN() -STD_PHP_INI_BOOLEAN("apc.enabled", "1", PHP_INI_ALL, OnUpdateInt, enabled, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.shm_segments", "1", PHP_INI_SYSTEM, OnUpdateInt, shm_segments, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.shm_size", "30", PHP_INI_SYSTEM, OnUpdateInt, shm_size, zend_apc_globals, apc_globals) -STD_PHP_INI_BOOLEAN("apc.optimization", "0", PHP_INI_ALL, OnUpdateInt, optimization, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.num_files_hint", "1000", PHP_INI_SYSTEM, OnUpdateInt, num_files_hint, zend_apc_globals, apc_globals) +STD_PHP_INI_BOOLEAN("apc.enabled", "1", PHP_INI_ALL, OnUpdateBool, enabled, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.shm_segments", "1", PHP_INI_SYSTEM, OnUpdateInt, shm_segments, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.shm_size", "30", PHP_INI_SYSTEM, OnUpdateInt, shm_size, zend_apc_globals, apc_globals) +STD_PHP_INI_BOOLEAN("apc.optimization", "0", PHP_INI_ALL, OnUpdateInt, optimization, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.num_files_hint", "1000", PHP_INI_SYSTEM, OnUpdateInt, num_files_hint, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.user_entries_hint", "100", PHP_INI_SYSTEM, OnUpdateInt, user_entries_hint, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.gc_ttl", "3600", PHP_INI_SYSTEM, OnUpdateInt, gc_ttl, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, ttl, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.user_ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, user_ttl, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.gc_ttl", "3600", PHP_INI_SYSTEM, OnUpdateInt, gc_ttl, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, ttl, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.user_ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, user_ttl, zend_apc_globals, apc_globals) #if APC_MMAP -STD_PHP_INI_ENTRY("apc.mmap_file_mask", NULL, PHP_INI_SYSTEM, OnUpdateString, mmap_file_mask, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.mmap_file_mask", NULL, PHP_INI_SYSTEM, OnUpdateString, mmap_file_mask, zend_apc_globals, apc_globals) #endif PHP_INI_ENTRY("apc.filters", NULL, PHP_INI_SYSTEM, OnUpdate_filters) -STD_PHP_INI_BOOLEAN("apc.cache_by_default", "1", PHP_INI_SYSTEM, OnUpdateInt, cache_by_default, zend_apc_globals, apc_globals) +STD_PHP_INI_BOOLEAN("apc.cache_by_default", "1", PHP_INI_SYSTEM, OnUpdateBool, cache_by_default, zend_apc_globals, apc_globals) STD_PHP_INI_BOOLEAN("apc.slam_defense", "0", PHP_INI_SYSTEM, OnUpdateInt, slam_defense, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.file_update_protection", "2", PHP_INI_SYSTEM, OnUpdateInt,file_update_protection, zend_apc_globals, apc_globals) -STD_PHP_INI_BOOLEAN("apc.enable_cli", "0", PHP_INI_SYSTEM, OnUpdateInt, enable_cli, zend_apc_globals, apc_globals) -STD_PHP_INI_ENTRY("apc.max_file_size", "1M", PHP_INI_SYSTEM, OnUpdateInt, max_file_size, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.file_update_protection", "2", PHP_INI_SYSTEM, OnUpdateInt,file_update_protection, zend_apc_globals, apc_globals) +STD_PHP_INI_BOOLEAN("apc.enable_cli", "0", PHP_INI_SYSTEM, OnUpdateBool, enable_cli, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.max_file_size", "1M", PHP_INI_SYSTEM, OnUpdateInt, max_file_size, zend_apc_globals, apc_globals) +STD_PHP_INI_BOOLEAN("apc.stat", "1", PHP_INI_SYSTEM, OnUpdateBool, fpstat, zend_apc_globals, apc_globals) PHP_INI_END() /* }}} */ @@ -175,7 +177,7 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.74.2.1 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.74.2.2 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -191,7 +193,7 @@ /* Disable APC in cli mode unless overridden by apc.enable_cli */ if(!APCG(enable_cli) && !strcmp(sapi_module.name, "cli")) { - zend_alter_ini_entry("apc.enabled", sizeof("apc.enabled"), "0", 2, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); + zend_alter_ini_entry("apc.enabled", sizeof("apc.enabled"), "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); } if (APCG(enabled)) { @@ -268,6 +270,7 @@ add_assoc_long(return_value, "num_hits", info->num_hits); add_assoc_long(return_value, "num_misses", info->num_misses); add_assoc_long(return_value, "start_time", info->start_time); + add_assoc_long(return_value, "expunges", info->expunges); ALLOC_INIT_ZVAL(list); array_init(list); @@ -373,7 +376,18 @@ add_assoc_long(return_value, "num_seg", info->num_seg); add_assoc_long(return_value, "seg_size", info->seg_size); add_assoc_long(return_value, "avail_mem", apc_sma_get_avail_mem()); - +#if ALLOC_DISTRIBUTION + { + size_t *adist = apc_sma_get_alloc_distribution(); + zval* list; + ALLOC_INIT_ZVAL(list); + array_init(list); + for(i=0; i<30; i++) { + add_next_index_long(list, adist[i]); + } + add_assoc_zval(return_value, "adist", list); + } +#endif ALLOC_INIT_ZVAL(block_lists); array_init(block_lists); @@ -439,7 +453,6 @@ if (!apc_cache_user_insert(apc_user_cache, key, entry, t TSRMLS_CC)) { APCG(mem_size_ptr) = NULL; - apc_cache_free_user_key(&key); apc_cache_free_entry(entry); apc_cache_expunge(apc_cache,t); apc_cache_expunge(apc_user_cache,t); @@ -447,7 +460,6 @@ } APCG(mem_size_ptr) = NULL; - entry->mem_size = mem_size; return 1; @@ -508,7 +520,7 @@ entry = apc_cache_user_find(apc_user_cache, strkey, strkey_len + 1, t); if(entry) { /* deep-copy returned shm zval to emalloc'ed return_value */ - apc_copy_zval(return_value, entry->data.user.val, apc_php_malloc, apc_php_free); + apc_cache_fetch_zval(return_value, entry->data.user.val, apc_php_malloc, apc_php_free); apc_cache_release(apc_user_cache, entry); } else { RETURN_FALSE;
« previous php.pecl.cvs (#5423) next »