PHP APC 缓存不保留任何变量



我一定错过了一些明显的东西。我的APC安装正确,并且显示在phpinfo()中很好。我目前正在 apache 上运行带有 APC 3.1.13 的 php 5.4.20。这是一个面板安装,所以也要记住这一点。

主要问题是缓存正常工作,但仅在页面加载期间。 如果我运行

<?php
    apc_store('foo', 'bar');
    echo apc_fetch('foo');
?>

它会回显出变量,但是如果我注释掉apc_store并再次运行代码,则不会显示任何内容,var_dump显示布尔值(false);

我也尝试过这段代码,以防万一我在做一些愚蠢的事情,这也不起作用。它总是显示"从缓存中找不到 str...节省"

// Check if str found from cache
    if (apc_exists('str')) {
        // Print str from cache
        echo "str from cache: ", apc_fetch('str'), "<br />";
        // Clear cache
        apc_clear_cache('user');
        // Try to fetch str again
        echo "str from cache, after user cache is cleared: ", "<br />";
        var_dump(apc_fetch('str'));
    }
    else {
        // Save str to cache and set ttl 120 seconds
        echo 'str not found from cache...saving', "<br />";
        $str = "This is just test";
        apc_store('str', $str, 120);
    }

我的 apc 配置如下...

apc
APC Support => disabled
Version => 3.1.13
APC Debugging => Disabled
MMAP Support => Enabled
MMAP File Mask =>  
Locking type => pthread read/write Locks
Serialization Support => broken
Revision => $Revision: 327136 $
Build Date => Oct 17 2013 16:47:57
Directive => Local Value => Master Value
apc.cache_by_default => Off => Off
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
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 => 512 => 512
apc.shm_strings_buffer => 4M => 4M
apc.slam_defense => Off => Off
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 是否在已经安装了 apc 的生产服务器上正常工作。事实上,它正在按应有的方式工作。所以我运行了 php_sapi_name(),在生产服务器上它是 apache2handler,而在开发服务器(我目前正在使用的服务器)上,它使用的是 cgi-fcgi,这可能是问题的原因。由于我使用的是cPanel,我应该能够简单地将PHP"处理程序"从suPHP更改为DSO,之后它应该可以工作。生产服务器不使用cpanel,只是很好的老式....的。。。。。非cPanel的东西,使其工作。

您需要使用 APC Web 界面来调试此问题。

找到一个名为 apc 的文件.php

find / -name apc.php

现在将其复制到您的 www/文件夹并在浏览器中加载它。

(下面是它的外观示例:http://andrewdunkle.com/apc.php )

现在,重试脚本并检查变量是否已正确存储并且到期日期是否较长。还要测试系统缓存是否在每次页面加载时被重置。(APC.php 或您的其他脚本。

最后,尝试在 apache 中从 worker 切换到 prefork。(或者相反,如果你使用prefork)

我找到了这个回答我问题的线程。根本问题是,当我需要在 DSO/mod_php 下正确运行 APC 时,我在 CGI-FCGI 下运行。在 Cpanel 上更改它是一头野兽,因为当您更改 php 处理程序时,apc.so 扩展导致该部分失败。亚尔。

最新更新