|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-28 19:16 UTC] ken at smallboxcms dot com
Description:
------------
apc_store / apc_fetch no longer retrieves anything if an empty array is stored.
Reproduce code:
---------------
$foo = array();
apc_store('foo', $foo);
$bar = apc_fetch('foo');
print_r($bar);
Expected result:
----------------
on 3.0 displays an empty array, but in 3.1.4 it does not. This results in a cache slam error as we can no longer indicate that a value is empty.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 18:00:02 2025 UTC |
So it's failing for me too if I use it as if(!($val = apc_fetch('foo'))) { print "Gotcha!\n"; } mainly because php -r 'if(!array()) { print "Gotcha!\n";}' is a damn nasty gotcha.Can't reproduce anything like this. I suspect that this was due to the apc.slam_defense for user cache. Check for return value of apc_store() as well. If it returns true & apc_exists('foo') is true, then we have a real bug, otherwise it's probably a write to the error_log about a key slam.I turned off slam_defense because of this. But I got around the problem hitting the cache if the result set is an array (sql doesn't return anything). Because the sql result set is empty the cache is loaded and returns an empty array and runs the sql everytime instead of caching the empty result set. //Zend code for $cache->load is a wrapper for apc_fetch function() { $cached_values = $cache->load($cache_key); if(!($cached_values) && !is_array($cached_values)) { hit db and save to cache } return cache value } The most important part is !is_array($cached_values), so only if the cache is NULL and NOT an array then hit the database;