为什么apc_cache_info()没有列出任何缓存文件?(CLI)


why is apc_cache_info() not listing any cached files? (CLI)

所有的命令都是在Debian系统上通过CLI执行的

get_loaded_extensions()列出了"apc"和我的 apc - CLI的设置:

apc
APC Support => enabled
Version => 3.1.7
APC Debugging => Disabled
MMAP Support => Enabled
MMAP File Mask =>
Locking type => pthread mutex Locks
Serialization Support => php
Revision => $Revision: 307215 $
Build Date => Feb 27 2011 19:39:21
Directive => Local Value => Master Value
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => On => On
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On

清除APC:

php -r "print_r(apc_clear_cache());"

为"1"。

执行一个非常简单的php文件 "test.php":

php test.php

但现在执行 apc_cache_info ():

php -r "print_r(apc_cache_info());"

显示没有缓存数据似乎:

Array
(
    [num_slots] => 1031
    [ttl] => 0
    [num_hits] => 0
    [num_misses] => 0
    [num_inserts] => 0
    [expunges] => 0
    [start_time] => 1322733678
    [mem_size] => 0
    [num_entries] => 0
    [file_upload_progress] => 1
    [memory_type] => mmap
    [locking_type] => pthread mutex Locks
    [cache_list] => Array
        (
        )
    [deleted_list] => Array
        (
        )
    [slot_distribution] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
[... ever value is 0 ... ]

为什么会这样?

我想做的是在CLI上使用APC,缓存文件的操作码,然后"看到"已经缓存的东西。

关于系统和PHP的更多信息:

phpinfo()
PHP Version => 5.3.8-1+b1
System => Linux debian 3.1.0-1-686-pae #1 SMP Tue Nov 29 19:01:56 UTC 2011 i686
Build Date => Nov 13 2011 10:54:57
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /etc/php5/cli/conf.d
Additional .ini files parsed => /etc/php5/cli/conf.d/apc.ini,
/etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/gd.ini,
/etc/php5/cli/conf.d/imagick.ini,
/etc/php5/cli/conf.d/intl.ini,
/etc/php5/cli/conf.d/mcrypt.ini,
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/suhosin.ini,
/etc/php5/cli/conf.d/xdebug.ini
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,NTS
PHP Extension Build => API20090626,NTS
Debug Build => no
Thread Safety => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => disabled
IPv6 Support => enabled

好吧,看来CLI的进程间痴呆了。

这意味着运行以下脚本"main.php":

<?php
apc_clear_cache();
print_r(apc_cache_info());
require "test.php";
print_r(apc_cache_info());

将给出最后一行:

Array
(
    [num_slots] => 1031
    [ttl] => 0
    [num_hits] => 0
    [num_misses] => 1
    [num_inserts] => 2
    [expunges] => 0
    [start_time] => 1322734705
    [mem_size] => 4168
    [num_entries] => 1
    [file_upload_progress] => 1
    [memory_type] => mmap
    [locking_type] => pthread mutex Locks
    [cache_list] => Array
        (
            [0] => Array
                (
                    [type] => file
                    [device] => 2049
                    [inode] => 26472
                    [filename] => /root/test.php
                    [num_hits] => 0
                    [mtime] => 1322658338
                    [creation_time] => 1322734705
                    [deletion_time] => 0
                    [access_time] => 1322734705
                    [ref_count] => 0
                    [mem_size] => 4168
                )
        )
    [deleted_list] => Array
        (
        )
[...]

CLI脚本创建一个APC段,它在脚本结束时被销毁。因此,运行另一个脚本来显示APC信息将创建一个没有数据的新段。

你不能在CLI中使用APC缓存,它的内存只保存在服务器池中(PHP- fpm, Apache+PHP, Lighttpd+FastCGI…)。例如,以下是我如何在cron脚本中管理APC缓存的示例:https://www.dugwood.com/949904-php5-opcode-caching-and-memory-storage-with-apc-xcache-in-command-line-interface-cli-or-cron.html

如果你在你用CLI调用的脚本中运行apc_cache_info(),你可以实现看到变量。在大多数情况下,APC在CLI中是无用的,它只是用于调试目的(并且作为默认的APC)。