php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63018 APCIterator ignores user defined keys after system's TTL is reached
Submitted: 2012-09-05 17:47 UTC Modified: 2013-04-22 07:12 UTC
Votes:14
Avg. Score:3.8 ± 1.3
Reproduced:7 of 8 (87.5%)
Same Version:2 (28.6%)
Same OS:3 (42.9%)
From: andres dot barcenas at miniclip dot com Assigned:
Status: No Feedback Package: APC (PECL)
PHP Version: 5.3Git-2012-09-05 (snap) OS: CentOS 6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
37 + 16 = ?
Subscribe to this entry?

 
 [2012-09-05 17:47 UTC] andres dot barcenas at miniclip dot com
Description:
------------
There seems to be a bug with APCIterator a specific version of PHP 5.3.3 and APC:

php-5.3.3-14.el6_3.x86_64
php-pecl-apc-3.1.9-2.el6.x86_64

apc.ini:

-- snip --
; Enable apc extension module
extension = apc.so

; Options for the APC module version >= 3.1.3

; This can be set to 0 to disable APC. 
apc.enabled=1
; The number of shared memory segments to allocate for the compiler cache. 
apc.shm_segments=1
; The size of each shared memory segment in MB.
apc.shm_size=256
; A "hint" about the number of distinct source files that will be included or 
; requested on your web server. Set to zero or omit if you're not sure;
apc.num_files_hint=1024
; Just like num_files_hint, a "hint" about the number of distinct user cache
; variables to store.  Set to zero or omit if you're not sure;
apc.user_entries_hint=4096
; The number of seconds a cache entry is allowed to idle in a slot in case this
; cache entry slot is needed by another entry.
apc.ttl=7200
; use the SAPI request start time for TTL
apc.use_request_time=1
; The number of seconds a user cache entry is allowed to idle in a slot in case
; this cache entry slot is needed by another entry.
apc.user_ttl=7200
; The number of seconds that a cache entry may remain on the garbage-collection 
list. 
apc.gc_ttl=3600
; On by default, but can be set to off and used in conjunction with positive
; apc.filters so that files are only cached if matched by a positive filter.
apc.cache_by_default=1
; A comma-separated list of POSIX extended regular expressions.
apc.filters
; The mktemp-style file_mask to pass to the mmap module 
apc.mmap_file_mask=/dev/zero
; This file_update_protection setting puts a delay on caching brand new files.
apc.file_update_protection=2
; Setting this enables APC for the CLI version of PHP (Mostly for testing and 
debugging).
apc.enable_cli=0
; Prevents large files from being cached
apc.max_file_size=1M
; Whether to stat the main script file and the fullpath includes.
apc.stat=1
; Vertification with ctime will avoid problems caused by programs such as svn or 
rsync by making 
; sure inodes havn't changed since the last stat. APC will normally only check 
mtime.
apc.stat_ctime=0
; Whether to canonicalize paths in stat=0 mode or fall back to stat behaviour
apc.canonicalize=0
; With write_lock enabled, only one process at a time will try to compile an 
; uncached script while the other processes will run uncached
apc.write_lock=1
; Logs any scripts that were automatically excluded from being cached due to 
early/late binding issues.
apc.report_autofilter=0
; RFC1867 File Upload Progress hook handler
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
; Optimize include_once and require_once calls and avoid the expensive system 
calls used.
apc.include_once_override=0
apc.lazy_classes=00
apc.lazy_functions=0
; not documented
apc.coredump_unmap=0
apc.file_md5=0
apc.preload_path
apc.slam_defense=0

-- snip --

All user defined keys are set without an actual expiration time which means that 
they will never expire unless Apache is restarted. For some odd reason, when the 
user define keys goes over the TTL set on the system (See above apc.ini) and the 
Gargage Collection kicks in, it makes it invisible and APCIterator does not 
contain it. 

	foreach (new APCIterator('user', '/'. $cache_key . '/', APC_ITER_KEY, 5) 
as $counter) {
			apc_delete($counter['key']);
		}

I have tried downgrading to previous PHP version and it works without a problem:

php-pecl-memcache
php


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-05 17:48 UTC] pajoye@php.net
Please try with APC 3.1.13
 [2012-09-05 17:48 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-09-05 17:48 UTC] andres dot barcenas at miniclip dot com
-Status: Feedback +Status: Open
 [2012-09-05 17:48 UTC] andres dot barcenas at miniclip dot com
PHP version currently used that works without a problem:

php-5.3.3-3.el6_2.8.x86_64

php-pecl-apc-3.1.3p1-1.2.el6.1.x86_64
 [2012-09-05 17:49 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-11-11 16:02 UTC] andres dot barcenas at miniclip dot com
I do not compile custom packages. I would need an RPM built for CentOS 6 and php 
5.3
 [2013-02-18 00:36 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.
 [2013-04-19 00:19 UTC] tubalmartin at gmail dot com
I can confirm this odd behaviour.

APCIterator only iterates through user defined keys that are "fresher" than the 
apc.user_ttl configuration value.

I'm using APC 3.1.13 and PHP 5.4.13.
 [2013-04-22 07:12 UTC] gopalv@php.net
Let me get this straight.

You do an apc_add("key", "value"); without a TTL.

Then the iterator drops off items when the apc.user_ttl (3600 s) expires?

That sounds like a corner case issue. The cache really should expire items when 
user_ttl is hit.

It would be a bug if the item is accessible via apc_fetch(), but not via apc 
iterator.
 [2013-04-25 12:44 UTC] tubalmartin at gmail dot com
The thing is user cache entries can be fetched with apc_fetch() even if they are 
stale (after apc.user_ttl time has passed). I don't know if that is the expected 
behaviour or not.

We're using APC to store user sessions and we observed APCIterator ignored user 
entries older than apc.user_ttl time.

Our garbage collector routine is custom. We're now using apc_user_info('user'), 
apc_fetch() and apc_delete() to make it work as expected and indeed it works. 
However, we couldn't get the same result with APCIterator (ignores "stale" user 
entries without a TTL).
 [2013-04-25 14:55 UTC] tubalmartin at gmail dot com
I suppose APCIterator will not ignore user entries if we set apc.user_ttl to 0.
 [2013-08-07 06:25 UTC] torton at eyedro dot com
I've seen this twice now.  At this moment, I can see 1,000 user variables in the 
apc cache that are accessible via apc_fetch(), yet they are not accessible via 
the code below ($iCnt is 0).  How this started was that there was an unrelated 
bug in our code that allowed the apc cache to build up about 3,000 variables.  
When I fixed the code and refreshed the opcode cache all but the oldest apc 
variables were correctly retrieved and processed.  I've also included our apc 
config that shows the ttl values are 1-2 hours and inline with what was 
described by another user.  OS/PHP versions below config info.

$oTmp = new APCIterator('user', '|(.*)|', APC_ITER_KEY|APC_ITER_VALUE, 10000, 
APC_LIST_ACTIVE);
$iCnt = $oTmp->getTotalCount();


; Enable apc extension module
extension = apc.so

; Options for the APC module version >= 3.1.3
; See http://www.php.net/manual/en/apc.configuration.php

; This can be set to 0 to disable APC. 
apc.enabled=1

; The number of shared memory segments to allocate for the compiler cache. 
apc.shm_segments=1

; The size of each shared memory segment, with M/G suffixe
apc.shm_size=128M

; A "hint" about the number of distinct source files that will be included or 
; requested on your web server. Set to zero or omit if you are not sure;
apc.num_files_hint=1000

; Just like num_files_hint, a "hint" about the number of distinct user cache
; variables to store.  Set to zero or omit if you are not sure;
apc.user_entries_hint=10000

; The number of seconds a cache entry is allowed to idle in a slot in case this
; cache entry slot is needed by another entry.
apc.ttl=7200

; use the SAPI request start time for TTL
apc.use_request_time=1

; The number of seconds a user cache entry is allowed to idle in a slot in case
; this cache entry slot is needed by another entry.
apc.user_ttl=7200

; The number of seconds that a cache entry may remain on the garbage-collection 
list. 
apc.gc_ttl=3600

; On by default, but can be set to off and used in conjunction with positive
; apc.filters so that files are only cached if matched by a positive filter.
apc.cache_by_default=1

; A comma-separated list of POSIX extended regular expressions.
apc.filters

; The mktemp-style file_mask to pass to the mmap module 
apc.mmap_file_mask=/tmp/apc.XXXXXX

; This file_update_protection setting puts a delay on caching brand new files.
apc.file_update_protection=2

; Setting this enables APC for the CLI version of PHP (Mostly for testing and 
debugging).
apc.enable_cli=0

; Prevents large files from being cached
apc.max_file_size=16M

; Whether to stat the main script file and the fullpath includes.
apc.stat=0

; Vertification with ctime will avoid problems caused by programs such as svn or 
rsync by making 
; sure inodes have not changed since the last stat. APC will normally only check 
mtime.
apc.stat_ctime=0

; Whether to canonicalize paths in stat=0 mode or fall back to stat behaviour
apc.canonicalize=0

; With write_lock enabled, only one process at a time will try to compile an 
; uncached script while the other processes will run uncached
apc.write_lock=1

; Logs any scripts that were automatically excluded from being cached due to 
early/late binding issues.
apc.report_autofilter=0

; RFC1867 File Upload Progress hook handler
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600

; Optimize include_once and require_once calls and avoid the expensive system 
calls used.
apc.include_once_override=0
apc.lazy_classes=0
apc.lazy_functions=0

; Enables APC handling of signals, such as SIGSEGV, that write core files when 
signaled. 
; APC will attempt to unmap the shared memory segment in order to exclude it 
from the core file
apc.coredump_unmap=0

; Records a md5 hash of files. 
apc.file_md5=0

; not documented
apc.preload_path

Server version: Apache/2.4.4 (Amazon)
Server built:   May 21 2013 16:44:09
PHP Version => 5.4.17
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 02:01:29 2024 UTC