php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59483 apc_store no longer stores empty arrays
Submitted: 2010-10-28 19:16 UTC Modified: 2013-02-18 00:35 UTC
From: ken at smallboxcms dot com Assigned:
Status: No Feedback Package: APC (PECL)
PHP Version: 5.2.9 OS: RHEL 5
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.  


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-10 13:03 UTC] gopalv82 at yahoo dot com
I can confirm that it works for me with 3.1.5 at least.

Are you sure you don't have suhosin installed?

It has been known to break apc badly.
 [2010-11-10 13:15 UTC] gopalv82 at yahoo dot com
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.
 [2010-11-10 14:07 UTC] ken at smallboxcms dot com
Not using suhosin. Also, the below gotcha does not apply. This is a matter of it returning null (or similar) instead of an empty array. Had to go back to 3.0.19 - so can't quickly check if it has been fixed.
 [2010-12-01 04:38 UTC] gopalv@php.net
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.
 [2011-04-15 13:03 UTC] marko dot vujo at gmail dot com
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;
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC