|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-26 23:54 UTC] dave at hobodave dot com
Description:
------------
After upgrading to APC 3.1.3p1 when running my unit tests I am
spammed by over a thousand of the following message:
[Wed Aug 26 22:48:22 2009] [apc-warning] Potential cache slam
averted for key 'foo' in /Users/hobodave/foo.php on line 3.
Also subsequent attempts to set the same key in the user cache
will result in the second failing.
Reproduce code:
---------------
<?php
apc_store('foo', 1);
apc_store('foo', 2);
echo apc_fetch('foo');
Expected result:
----------------
2
Actual result:
--------------
[Wed Aug 26 22:48:22 2009] [apc-warning] Potential cache slam
averted for key 'foo' in /Users/hobodave/foo.php on line 3.
1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 12:00:01 2025 UTC |
I have just tried SVN trunk as of today ("svn info" deets below)... same fail case as 3.1.3p1 -> calling apc_store with the same key twice fails. Last Changed Author: pajoye Last Changed Rev: 289714 Last Changed Date: 2009-10-18 02:33:20 +1100 (Sun, 18 Oct 2009)whoa, jdub? I'm in distinguished company here :) I think I know what's up, so to speak. ini_set() does not work for any of apc settings because they are set for PHP_INI_SYSTEM and cannot be overridden. I should change that for slam_defense. But when I do dump apc.slam_defense = Off; in my apc.ini or when I set it with -d, it does work without errors (fresh svn build, cli mode). $ /opt/php53/bin/php -dapc.slam_defense=off apc-store-test.txt <pre> apc_store('test', 'one'): 1 apc_store('test', 'two'): 1 apc_store('diff', 'thr'): 1 </pre> you can find me on irc in case you need more help. So, if I work out a fix for this bug ... can you get me a discount for LCA this year? #bribesaccepted ;)Can't get rid of this warning via apc.slam_defense=off <?php var_dump('slam_defense: ', ini_get('apc.slam_defense')); var_dump('write_lock: ', ini_get('apc.write_lock')); apc_store('foo', 1); apc_store('foo', 2); echo apc_fetch('foo') . PHP_EOL; ?> Outputs <pre> string(14) "slam_defense: " bool(false) string(12) "write_lock: " string(0) "" 1 [Fri May 7 13:32:14 2010] [apc-warning] Potential cache slam averted for key 'foo' in /home/conf/limb_rep/limb/limb/test.php on line 6. </pre> I'm using APC 3.1.3p1 on PHP 5.3.2-1ubuntu4.1 on Ubuntu Lucid x86. apc.ini contents: <pre> extension=apc.so apc.enabled = On apc.enable_cli = On apc.slam_defense = Off apc.write_lock = Off </pre>Getting tons of this messages. My application logic is broken because this bug, Going to use memcached instead until this bug is resolved. php 5.3.3 apc 3.1.3p1 >apc_store("x",1) true > apc_store("x",1) [Wed Jun 16 11:06:52 2010] [apc-warning] Potential cache slam averted for key 'x' false apc.slam_defense = Off apc.write_lock = Off PS: i tried to do: if(!$put) { /* APC BUG WORKAROUND !! */ apc_delete($key); $put=apc_store($key,$val,$timeout); if(!$put) { Log::warning( ... ); } } but it still does not workFYI: apc.slam_defense isn't in the source code anymore. So setting it is like doing nothing. We wanted it back (unit tests an other things) so maybe you want patch the source code with this: ----------------------------------------------------------- --- a/APC-3.1.3p1/apc_cache.c +++ b/APC-3.1.3p1/apc_cache.c @@ -1144,6 +1144,10 @@ unsigned int keylen = key->data.user.identifier_len+1; unsigned int h = string_nhash_8(key->data.user.identifier, keylen); + if(!APCG(slam_defense)) { + return 0; + } + /* unlocked reads, but we're not shooting for 100% success with this */ if(lastkey->h == h && keylen == lastkey->keylen) { if(lastkey->mtime == t) { --- a/APC-3.1.3p1/apc_globals.h +++ b/APC-3.1.3p1/apc_globals.h @@ -86,6 +86,7 @@ zend_bool canonicalize; /* true if relative paths should be canonicalized in no-stat mode */ zend_bool stat_ctime; /* true if ctime in addition to mtime should be checked */ zend_bool write_lock; /* true for a global write lock */ + zend_bool slam_defense; /* true for ignoring possible slam defense */ zend_bool report_autofilter; /* true for auto-filter warnings */ zend_bool include_once; /* Override the ZEND_INCLUDE_OR_EVAL opcode handler to avoid pointless fopen()s [still experimental] */ apc_optimize_function_t apc_optimize_function; /* optimizer function callback */ --- a/APC-3.1.3p1/php_apc.c +++ b/APC-3.1.3p1/php_apc.c @@ -91,6 +91,7 @@ apc_globals->canonicalize = 1; apc_globals->stat_ctime = 0; apc_globals->write_lock = 1; + apc_globals->slam_defense = 0; apc_globals->report_autofilter = 0; apc_globals->include_once = 0; apc_globals->apc_optimize_function = NULL; @@ -199,6 +200,7 @@ STD_PHP_INI_BOOLEAN("apc.canonicalize", "1", PHP_INI_SYSTEM, OnUpdateBool, canonicalize, zend_apc_globals, apc_globals) STD_PHP_INI_BOOLEAN("apc.stat_ctime", "0", PHP_INI_SYSTEM, OnUpdateBool, stat_ctime, zend_apc_globals, apc_globals) STD_PHP_INI_BOOLEAN("apc.write_lock", "1", PHP_INI_SYSTEM, OnUpdateBool, write_lock, zend_apc_globals, apc_globals) +STD_PHP_INI_BOOLEAN("apc.slam_defense", "0", PHP_INI_SYSTEM, OnUpdateBool, slam_defense, zend_apc_globals, apc_globals) STD_PHP_INI_BOOLEAN("apc.report_autofilter", "0", PHP_INI_SYSTEM, OnUpdateBool, report_autofilter,zend_apc_globals, apc_globals) #ifdef MULTIPART_EVENT_FORMDATA STD_PHP_INI_BOOLEAN("apc.rfc1867", "0", PHP_INI_SYSTEM, OnUpdateBool, rfc1867, zend_apc_globals, apc_globals)This issue, aside from filling up logs, is a headache when developing. If, as a good developer, you have error reporting displaying everything, then this error will usually create output that is sent before the headers are, which pretty much "breaks" the response as a chain of errors proceed to occur. Therefore, I developed a patch for APC 3.1.7 that I am forced to run with. The patch makes it so that the errors are still written to PHP's standard error log, but don't clobber the HTTP response output. Perhaps this will be useful to someone: diff -u -r APC-3.1.7/apc_cache.c APC-3.1.7-patched/apc_cache.c --- APC-3.1.7/apc_cache.c 2011-01-11 12:06:38.000000000 -0700 +++ APC-3.1.7-patched/apc_cache.c 2011-01-21 18:49:40.000000000 -0700 @@ -1270,6 +1270,7 @@ /* {{{ apc_cache_is_last_key */ zend_bool apc_cache_is_last_key(apc_cache_t* cache, apc_cache_key_t* key, unsigned int h, time_t t TSRMLS_DC) { + char *log_message; apc_keyid_t *lastkey = &cache->header->lastkey; unsigned int keylen = key->data.user.identifier_len; #ifdef ZTS @@ -1288,7 +1289,10 @@ if(lastkey->mtime == t && FROM_DIFFERENT_THREAD(lastkey)) { /* potential cache slam */ if(APCG(slam_defense)) { - apc_warning("Potential cache slam averted for key '%s'" TSRMLS_CC, key->data.user.identifier); + log_message = emalloc((key->data.user.identifier_len + 40) * sizeof(char)); + sprintf(log_message, "Potential cache slam averted for key '%s'", key->data.user.identifier); + php_log_err(log_message TSRMLS_CC); + efree(log_message); return 1; } } By the way, I have provided another patch that addresses a similar issue here: http://pecl.php.net/bugs/bug.php?id=16966