php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59466 APC sometimes stores "false".
Submitted: 2010-10-17 08:45 UTC Modified: 2010-11-16 12:16 UTC
From: vuliad at gmail dot com Assigned:
Status: Closed Package: APC (PECL)
PHP Version: 5.3.2 OS: freebsd
Private report: No CVE-ID: None
 [2010-10-17 08:45 UTC] vuliad at gmail dot com
Description:
------------
PHP Version 5.3.3 (cannot select it in phpversion here)


System	FreeBSD  6.3-STABLE FreeBSD 6.3-STABLE
PHP API	20090626
PHP Extension	20090626
Zend Extension	220090626
Zend Extension Build	API220090626,NTS
PHP Extension Build	API20090626,NTS

Version	3.1.4
MMAP Support	Enabled
MMAP File Mask	/tmp/apc.EyYwAm
Locking type	File Locks
Revision	$Revision: 301663 $
Build Date	Oct 12 2010 13:40:15

Directive	Local Value	
apc.cache_by_default	On	
apc.canonicalize	On	
apc.coredump_unmap	Off	
apc.enable_cli	Off	
apc.enabled	On	
apc.file_md5	Off	
apc.file_update_protection	2
apc.filters	no value	
apc.gc_ttl	3600	
apc.include_once_override	Off
apc.lazy_classes	Off	
apc.lazy_functions	Off	
apc.max_file_size	512M	
apc.mmap_file_mask	/tmp/apc.EyYwAm
apc.num_files_hint	1000	
apc.preload_path	no value
apc.report_autofilter	Off
apc.rfc1867	Off	
apc.rfc1867_freq	0	
apc.rfc1867_name	APC_UPLOAD_PROGRESS	
apc.rfc1867_prefix	upload_	
apc.rfc1867_ttl	3600	
apc.shm_segments	1
apc.shm_size	512M	
apc.slam_defense	Off	
apc.stat	On
apc.stat_ctime	Off
apc.ttl	0
apc.use_request_time	On
apc.user_entries_hint	4096
apc.user_ttl	0
apc.write_lock	On



_Sometimes_  apc_store saving "false" value.

apc_store("aaa","bbb") #returns true;
apc_fetch("aaa") #return false;

I write test(see Reproduce code) and results is:

storesTime: 0.00570511817932
testSteps: 100 
StrRepeat multiple: 1 
fetchTime: 0.00220680236816
stored: 100 values (100%)
exists: 5 values (5%)
fetched: 5 values (5%)


storesTime: 0.718439817429
testSteps: 10000 
StrRepeat multiple: 1 
fetchTime: 0.566982984543
stored: 10000 values (100%)
exists: 2528 values (25.28%)
fetched: 2528 values (25.28%)

after multiple refresh it always change beetween 2% and 90% 

The problem is that TOO many variables cannot be cashed.

Looking in apc.php for User Cache Entries there are more of 
Info	testKey98
Ttl	0
Type	user
Num Hits	0 (0.00%)
Mtime	2010/10/17 16:27:14
Creation Time	2010/10/17 16:27:14
Deletion Time	None
Access Time	2010/10/17 16:27:14
Ref Count	0
Mem Size	580
Stored Value	
false


The main problem here is that - Stored Value = false. Why 
it's false and what it mean?

There are some more strange thing:
If i clear user cache, User Cached Entries in apc.php gives 
"No data". BUT!! after store only one variable. and refresh 
in User Cached Entries - it shows Many other Keys that were 
stored before cache where flushed. it Stored Value gives 
FALSE and it cannot be deleted with apc_delete from User 
Cached Entries. 

Reproduce code:
---------------
<?php
$prefix="testKey";
$testSteps=100;
$multiple=1;


$storeSuccessCount=0;
$fetchSuccessCount=0;
$existsSuccessCount=0;
$start=microtime(true);
for($i=0;$i<=$testSteps-1;$i++)
{
if(apc_store($prefix.$i,str_repeat("a",$multiple*$i)))
						$storeSuccessCount++;
}
echo "storesTime: ".(microtime(true)-$start)."\n";

sleep(1);

$start=microtime(true);
for($i=0;$i<=$testSteps-1;$i++)
{

if(apc_fetch($prefix.$i))
	$existsSuccessCount++;

if($val=apc_fetch($prefix.$i))
	$fetchSuccessCount++;
	
}

echo "testSteps: ".$testSteps." \n";
echo "StrRepeat multiple: ".$multiple." \n";
echo "fetchTime: ".(microtime(true)-$start)."\n";
echo "stored: ".$storeSuccessCount." values (". (100*($storeSuccessCount/$testSteps))."%)\n";
echo "exists: ".$existsSuccessCount." values (". (100*($existsSuccessCount/$testSteps))."%)\n";
echo "fetched: ".$fetchSuccessCount." values (". (100*($fetchSuccessCount/$testSteps))."%)\n";
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-22 17:21 UTC] junk at 800lbgorilla dot com
I also experience this bug on different boxes w/PHP 5.2.6 and PHP 5.3.3.  APC version 3.1.4 (version 3.0.19 on these boxes works fine).

It happens so often that I've wrapped apc_store in a function that does the store, and then an immediate fetch to compare against what was just stored.  If it doesn't match, I repeat the store/fetch of the key until the values match.

I log the number of times it takes until the store is successful.  It seems to take between 1 and 7 tries, but eventually it will always work.  Most common is success after 1 retry.

It is not timing related... I've tired using a sleep(), etc., but the value will never show up no matter how long I give it (nor to different processes).  The only way to get the store to work it just repeat it over and over.


My function:

function _APCStore($key, $value) {
    $retries = 0;
    while ( 1 ) {
        apc_store($key, $value, 0);
        $test = apc_fetch($key);
        if ( $test != $value ) {
            error_log('EBB:_APCStore: Failed '.($retries+1).' times');
            $retries++;
            if ( $retries < 100 ) 
                continue;
            else
                _FatalError("EBB:_APCStore: Unable to store value into APC!");
        }
        break;
    }
}
 [2010-10-22 17:25 UTC] junk at 800lbgorilla dot com
I forgot to add that the apc_store call *always* returns true, even though it stores 'false' instead of what I passed it.
 [2010-10-27 00:31 UTC] sdfsdr at mailinator dot com
This is likely related to this bug: http://pecl.php.net/bugs/bug.php?id=18624

Many user variables end up cached multiple times, your apc_store is likely updating a different one than apc_fetch is returning. Until bug 18624 is fixed I would strongly avoid 3.1.4 as this is a huge cache integrity issue.
 [2010-11-10 13:42 UTC] gopalv82 at yahoo dot com
On 3.1.5, I kept getting 99% until I realized you are using an if() to compare. Changed your test to 

if(apc_fetch($prefix.$i) !== FALSE)

And it kept giving me 100%.

Please, please note that "" is == False
 [2010-11-15 20:05 UTC] junk at 800lbgorilla dot com
I can confirm that under 3.1.5 this issue is fixed for me!  Thanks guys!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 05:01:31 2024 UTC