Changeset 623 for branches/1.3/xcache.c
- Timestamp:
- 07/05/2009 10:41:16 AM (4 years ago)
- Location:
- branches/1.3
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
-
branches/1.3/xcache.c
r622 r623 87 87 88 88 static zend_bool xc_initized = 0; 89 static time_t xc_init_time = 0; 90 static long unsigned xc_init_instance_id = 0; 91 #ifdef ZTS 92 static long unsigned xc_init_instance_subid = 0; 93 #endif 89 94 static zend_compile_file_t *origin_compile_file = NULL; 90 95 static zend_compile_file_t *old_compile_file = NULL; … … 247 252 /* }}} */ 248 253 #endif 254 static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ */ 255 { 256 if (val + 1 >= count) { 257 return 0; 258 } 259 return val + 1; 260 } 261 /* }}} */ 262 static void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t period, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */ 263 { 264 time_t n = XG(request_time) / period; 265 if (*curtime != n) { 266 zend_uint target_slot = n % count; 267 if (n - *curtime > period) { 268 memset(counters, 0, sizeof(counters[0]) * count); 269 } 270 else { 271 zend_uint slot; 272 for (slot = advance_wrapped(*curslot, count); 273 slot != target_slot; 274 slot = advance_wrapped(slot, count)) { 275 counters[slot] = 0; 276 } 277 counters[target_slot] = 0; 278 } 279 *curtime = n; 280 *curslot = target_slot; 281 } 282 counters[*curslot] ++; 283 } 284 /* }}} */ 285 static void xc_cache_hit_dmz(xc_cache_t *cache TSRMLS_DC) /* {{{ */ 286 { 287 cache->hits ++; 288 289 xc_counters_inc(&cache->hits_by_hour_cur_time 290 , &cache->hits_by_hour_cur_slot, 60 * 60 291 , cache->hits_by_hour 292 , sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]) 293 TSRMLS_CC); 294 295 xc_counters_inc(&cache->hits_by_second_cur_time 296 , &cache->hits_by_second_cur_slot 297 , 1 298 , cache->hits_by_second 299 , sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]) 300 TSRMLS_CC); 301 } 302 /* }}} */ 249 303 250 304 /* helper function that loop through each entry */ … … 311 365 int i, c; 312 366 313 if (!xc_php_ttl || !xc_php_gc_interval ) {367 if (!xc_php_ttl || !xc_php_gc_interval || !xc_php_caches) { 314 368 return; 315 369 } … … 324 378 int i, c; 325 379 326 if (!xc_var_gc_interval ) {380 if (!xc_var_gc_interval || !xc_var_caches) { 327 381 return; 328 382 } … … 372 426 int i, c; 373 427 374 for (i = 0, c = xc_php_hcache.size; i < c; i ++) { 375 xc_gc_deletes_one(xc_php_caches[i] TSRMLS_CC); 376 } 377 378 for (i = 0, c = xc_var_hcache.size; i < c; i ++) { 379 xc_gc_deletes_one(xc_var_caches[i] TSRMLS_CC); 428 if (xc_php_caches) { 429 for (i = 0, c = xc_php_hcache.size; i < c; i ++) { 430 xc_gc_deletes_one(xc_php_caches[i] TSRMLS_CC); 431 } 432 } 433 434 if (xc_var_caches) { 435 for (i = 0, c = xc_var_hcache.size; i < c; i ++) { 436 xc_gc_deletes_one(xc_var_caches[i] TSRMLS_CC); 437 } 380 438 } 381 439 } … … 385 443 static void xc_fillinfo_dmz(int cachetype, xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */ 386 444 { 387 zval *blocks; 445 zval *blocks, *hits; 446 int i; 388 447 const xc_block_t *b; 389 448 #ifndef NDEBUG … … 417 476 add_assoc_null_ex(return_value, ZEND_STRS("gc")); 418 477 } 478 MAKE_STD_ZVAL(hits); 479 array_init(hits); 480 for (i = 0; i < sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]); i ++) { 481 add_next_index_long(hits, (long) cache->hits_by_hour[i]); 482 } 483 add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_hour"), hits); 484 485 MAKE_STD_ZVAL(hits); 486 array_init(hits); 487 for (i = 0; i < sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]); i ++) { 488 add_next_index_long(hits, (long) cache->hits_by_second[i]); 489 } 490 add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_second"), hits); 419 491 420 492 MAKE_STD_ZVAL(blocks); … … 640 712 static void xc_entry_unholds(TSRMLS_D) /* {{{ */ 641 713 { 642 xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size TSRMLS_CC); 643 xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC); 714 if (xc_php_caches) { 715 xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size TSRMLS_CC); 716 } 717 718 if (xc_var_caches) { 719 xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC); 720 } 644 721 } 645 722 /* }}} */ … … 914 991 TRACE("found %s, catch it", stored_xce->name.str.val); 915 992 xc_entry_hold_php_dmz(stored_xce TSRMLS_CC); 916 cache->hits ++;993 xc_cache_hit_dmz(cache); 917 994 break; 918 995 } … … 1222 1299 xc_shm_t *shm; 1223 1300 int i; 1224 if (!xc_initized) { 1225 return 0; 1226 } 1227 for (i = 0; i < xc_php_hcache.size; i ++) { 1228 shm = xc_php_caches[i]->shm; 1229 if (shm->handlers->is_readwrite(shm, p)) { 1230 return 1; 1231 } 1232 } 1233 for (i = 0; i < xc_var_hcache.size; i ++) { 1234 shm = xc_var_caches[i]->shm; 1235 if (shm->handlers->is_readwrite(shm, p)) { 1236 return 1; 1301 1302 if (xc_php_caches) { 1303 for (i = 0; i < xc_php_hcache.size; i ++) { 1304 shm = xc_php_caches[i]->shm; 1305 if (shm->handlers->is_readwrite(shm, p)) { 1306 return 1; 1307 } 1308 } 1309 } 1310 1311 if (xc_var_caches) { 1312 for (i = 0; i < xc_var_hcache.size; i ++) { 1313 shm = xc_var_caches[i]->shm; 1314 if (shm->handlers->is_readwrite(shm, p)) { 1315 return 1; 1316 } 1237 1317 } 1238 1318 } … … 1244 1324 xc_shm_t *shm; 1245 1325 int i; 1246 if (!xc_initized) { 1247 return 0; 1248 } 1249 for (i = 0; i < xc_php_hcache.size; i ++) { 1250 shm = xc_php_caches[i]->shm; 1251 if (shm->handlers->is_readonly(shm, p)) { 1252 return 1; 1253 } 1254 } 1255 for (i = 0; i < xc_var_hcache.size; i ++) { 1256 shm = xc_var_caches[i]->shm; 1257 if (shm->handlers->is_readonly(shm, p)) { 1258 return 1; 1326 1327 if (xc_php_caches) { 1328 for (i = 0; i < xc_php_hcache.size; i ++) { 1329 shm = xc_php_caches[i]->shm; 1330 if (shm->handlers->is_readonly(shm, p)) { 1331 return 1; 1332 } 1333 } 1334 } 1335 1336 if (xc_var_caches) { 1337 for (i = 0; i < xc_var_hcache.size; i ++) { 1338 shm = xc_var_caches[i]->shm; 1339 if (shm->handlers->is_readonly(shm, p)) { 1340 return 1; 1341 } 1259 1342 } 1260 1343 } … … 1515 1598 XG(internal_table_copied) = 1; 1516 1599 } 1517 if (xc_php_ hcache.size&& !XG(php_holds)) {1600 if (xc_php_caches && !XG(php_holds)) { 1518 1601 XG(php_holds) = calloc(xc_php_hcache.size, sizeof(xc_stack_t)); 1519 1602 for (i = 0; i < xc_php_hcache.size; i ++) { … … 1522 1605 } 1523 1606 1524 if (xc_ initized && xc_var_hcache.size&& !XG(var_holds)) {1607 if (xc_var_caches && !XG(var_holds)) { 1525 1608 XG(var_holds) = calloc(xc_var_hcache.size, sizeof(xc_stack_t)); 1526 1609 for (i = 0; i < xc_var_hcache.size; i ++) { … … 1675 1758 } 1676 1759 1677 #define STR " WWW-authenticate: Basic Realm=\"XCache Administration\""1760 #define STR "HTTP/1.0 401 Unauthorized" 1678 1761 sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); 1679 1762 #undef STR 1680 #define STR " HTTP/1.0 401 Unauthorized"1763 #define STR "WWW-authenticate: Basic Realm=\"XCache Administration\"" 1681 1764 sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); 1682 1765 #undef STR … … 1884 1967 } LEAVE_LOCK(xce.cache); 1885 1968 if (found) { 1886 xc e.cache->hits ++;1969 xc_cache_hit_dmz(xce.cache TSRMLS_CC); 1887 1970 } 1888 1971 else { … … 1965 2048 } LEAVE_LOCK(xce.cache); 1966 2049 if (found) { 1967 xc e.cache->hits ++;2050 xc_cache_hit_dmz(xce.cache TSRMLS_CC); 1968 2051 } 1969 2052 else { … … 2098 2181 } 2099 2182 /* }}} */ 2183 #ifdef HAVE_XCACHE_DPRINT 2184 /* {{{ proto bool xcache_dprint(mixed value) 2185 Prints variable (or value) internal struct (debug only) */ 2186 PHP_FUNCTION(xcache_dprint) 2187 { 2188 zval *value; 2189 2190 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { 2191 return; 2192 } 2193 xc_dprint_zval(value, 0 TSRMLS_CC); 2194 } 2195 /* }}} */ 2196 #endif 2100 2197 /* {{{ proto string xcache_asm(string filename) 2101 2198 */ … … 2323 2420 PHP_FE(xcache_isset, NULL) 2324 2421 PHP_FE(xcache_unset, NULL) 2422 #ifdef HAVE_XCACHE_DPRINT 2423 PHP_FE(xcache_dprint, NULL) 2424 #endif 2325 2425 {NULL, NULL, NULL} 2326 2426 }; … … 2460 2560 php_info_print_table_row(2, "Modules Built", XCACHE_MODULES); 2461 2561 php_info_print_table_row(2, "Readonly Protection", xc_readonly_protection ? "enabled" : "N/A"); 2562 ptr = php_format_date("Y-m-d H:i:s", sizeof("Y-m-d H:i:s") - 1, xc_init_time, 1 TSRMLS_CC); 2563 php_info_print_table_row(2, "Cache Init Time", ptr); 2564 efree(ptr); 2565 2566 #ifdef ZTS 2567 snprintf(buf, sizeof(buf), "%lu.%lu", xc_init_instance_id, xc_init_instance_subid); 2568 #else 2569 snprintf(buf, sizeof(buf), "%lu", xc_init_instance_id); 2570 #endif 2571 php_info_print_table_row(2, "Cache Instance Id", buf); 2462 2572 2463 2573 if (xc_php_size) { … … 2694 2804 } 2695 2805 xc_initized = 1; 2806 xc_init_time = time(NULL); 2807 xc_init_instance_id = getpid(); 2808 #ifdef ZTS 2809 xc_init_instance_subid = tsrm_thread_id(); 2810 #endif 2696 2811 } 2697 2812

