略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: APCIterator::__construct

2024-12-23

APCIterator::__construct

(PECL apc >= 3.1.1)

APCIterator::__construct构造一个 APCIterator 迭代器对象

说明

public APCIterator::__construct ( string $cache [, mixed $search = NULL [, int $format = APC_ITER_ALL [, int $chunk_size = 100 [, int $list = APC_LIST_ACTIVE ]]]] )

构造一个 APCIterator object.

参数

cache

缓存类型,可以是 user 或者 file。

search

匹配 APC 键名的 PCRE 正则表达式,既可以是单个正则表达式 string,也可以是 array 的正则表达式。或者可以是 NULL 来略过搜索。

format

需要的格式可以用一个或多个 APC_ITER_* 常量。

chunk_size

块的大小。必须是一个大于0的值,默认是100。

list

需要列出的类型。可以是 APC_LIST_ACTIVE 或 APC_LIST_DELETED。

返回值

成功时返回 APCIterator object,失败时返回 NULL。

范例

Example #1 APCIterator::__construct() 例子

<?php
foreach (new APCIterator('user''/^counter\./') as $counter) {
    echo 
"$counter[key]$counter[value]\n";
    
apc_dec($counter['key'], $counter['value']);
}
?>

参见

  • apc_exists() - 检查APC中是否存在某个或者某些key
  • apc_cache_info() - Retrieves cached information from APC's data store
add a noteadd a note

User Contributed Notes 3 notes

up
2
petabyte
7 years ago
With MAMP (using PHP 5.3.5 and APC 3.1.7) passing an array with multiple regex strings as $search arg always yields an empty APCIterator. Whereas passing a single string regex works. (Note: I only tried cache type 'user'.)

Workaround: Concatenated all regexes to single one with alternation. Example:

<?php
$results
= new APCIterator('user', '/^('.implode('|', $patterns).')');
?>
up
-2
puiumarius at gmail dot com
5 years ago
There is a bug in APCIterator: whatever the chunk size, APCIterator gets ALL keys matching the specified pattern (it seems that $chunk_size parameter is ignored).

Also, the documentation states that the default chunk size is 100, but even that is ignored.

Tested APC version is 3.1.13.

Example (I have 180 keys for this pattern in total):
$objIterator = new APCIterator('user', '/^key_prefix_\.*/', APC_ITER_ALL, 20);

If I itterate $objIterator  and then count() the results, I get 180.

Also, for:
$objIterator = new APCIterator('user', '/^key_prefix_\.*/');
Same count(), 180.

Even $objIterator->getTotalCount() returns 180.
up
-1
Anti Veeranna
8 years ago
Iterating (and specifically using current()) does not expunge cache entries for which $ttl has passed, you need to use apc_fetch to get rid of stale entries.

官方地址:https://www.php.net/manual/en/apciterator.construct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3