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

发布于 2024-12-19 03:22:38 字数 4240 浏览 2 评论 0原文

所有命令均通过 Debian 系统上的 CLI 执行。

get_loaded_extensions() 列出“apc”,我的 CLI 的 APC 设置 为:

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

All commands are executed via CLI on a Debian system.

get_loaded_extensions() lists "apc" and my APC-settings for the CLI are:

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

clear the APC:

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

gives "1".

execute a very simple PHP-file "test.php":

php test.php

but executing now apc_cache_info():

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

shows no cached data it seems:

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

why is that so?

What I want to do is to use APC on CLI, have a file's opcode cached and then "see" that something has been cached.

More information on system and 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆离笙 2024-12-26 03:22:38

好吧,看来 CLI 正在遭受 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
        (
        )
[...]

Okay, it seems like CLI is suffering from inter-process-dementia on CLI.

That means running the folling script "main.php":

<?php

apc_clear_cache();

print_r(apc_cache_info());

require "test.php";

print_r(apc_cache_info());

will give for the last line:

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
        (
        )
[...]
神回复 2024-12-26 03:22:38

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.enable_cli 在配置文件中处于关闭状态)。

A CLI script creates an APC segment, which is destroyed at the end of the script. Hence, running another script to show the APC info will create a new segment, with no data.

You can't use APC caching in a CLI, its memory is only kept within the server pool (PHP-FPM, Apache+PHP, Lighttpd+FastCGI...). For example, here's an example on how I manage to have APC caching in a cron script: https://www.dugwood.com/949904-php5-opcode-caching-and-memory-storage-with-apc-xcache-in-command-line-interface-cli-or-cron.html

If you run apc_cache_info() within the script you're calling with CLI, you can achieve to see the variables. In most cases, APC is useless in a CLI, it's just for debugging purposes (and as a default apc.enable_cli is off in the configuration file).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文