简体   繁体   English

CakePHP + APC用户缓存条目超时问题

[英]CakePHP + APC User Cache Entries Timeout Issue

I'm using CakePHP (version 1.3.8) and APC (version 3.1.3p1) with these settings: 我正在使用CakePHP(版本1.3.8)和APC(版本3.1.3p1)以及这些设置:

apc.ini apc.ini

extension=apc.so
apc.enabled=1
apc.enable_cli=0
apc.shm_size=128
apc.stat=0
apc.num_files_hint=10000
apc.user_entries_hint=10000
apc.max_file_size=5
apc.user_ttl = 3600
apc.ttl = 3600

Cake Core Settings: 蛋糕核心设置:

Cache::config('default', array(
        'engine' => 'Apc',
        'duration'=> '+5 minutes',
        'probability'=> 100,
        'prefix' => Inflector::slug(APP_DIR) . '_',
));

And for some reason, the timeout listed for the User Cache Entries (as viewed through mysite.com/apc.php) are all 86313600 seconds (999 days). 由于某种原因,为用户缓存条目列出的超时(通过mysite.com/apc.php查看)都是86313600秒(999天)。 I have no idea why it would be so high considering I've set both apc.user_ttl and apc.ttl in apc.ini and set the duration via Cake. 考虑到我在apc.ini中设置apc.user_ttl和apc.ttl并通过Cake设置持续时间,我不知道为什么会这么高。 I've tried clearing all of the APC caches and restarting Apache. 我已经尝试清除所有APC缓存并重新启动Apache。

Any assistance would be much appreciated. 任何援助将不胜感激。 Thanks. 谢谢。

Edit: thought it would be worth mentioning that the Runtime Settings shown through apc.php do have proper TTLs set as per the apc.ini config: 编辑:认为值得一提的是,通过apc.php显示的运行时设置确实根据apc.ini配置设置了正确的TTL:

apc.cache_by_default: 1
apc.canonicalize: 1
apc.coredump_unmap: 0
apc.enable_cli: 0
apc.enabled: 1
apc.file_md5: 0
apc.file_update_protection: 2
apc.filters 
apc.gc_ttl: 3600
apc.include_once_override: 0
apc.lazy_classes: 0
apc.lazy_functions: 0
apc.max_file_size: 5
apc.mmap_file_mask  
apc.num_files_hint: 10000
apc.preload_path
apc.report_autofilter: 0
apc.rfc1867: 0
apc.rfc1867_freq: 0
apc.rfc1867_name: APC_UPLOAD_PROGRESS
apc.rfc1867_prefix: upload_
apc.rfc1867_ttl: 3600
apc.shm_segments: 1
apc.shm_size: 128
apc.stat: 0
apc.stat_ctime: 0
apc.ttl: 3600
apc.use_request_time: 1
apc.user_entries_hint: 10000
apc.user_ttl: 3600
apc.write_lock: 1

I've figured out the issue, which ended up being confusion between what I think a "default" value should be and what CakePHP thinks a "default" value should be. 我已经找到了问题,最终我认为“默认”值应该与CakePHP认为“默认”值应该是什么之间存在混淆。

In cake/libs/cache.php, there is a write function which sets the key, value and duration of the cache entry, and passes it to the appropriate engine's write function (in this case APC). 在cake / libs / cache.php中,有一个write函数,用于设置缓存条目的键,值和持续时间,并将其传递给相应的引擎写入函数(在本例中为APC)。 In this function it checks the cache config settings from core.php to see if you've specified a duration there. 在此函数中,它检查core.php中的缓存配置设置,以查看是否已在此处指定了持续时间。 The code from core.php: core.php的代码:

Cache::config('default', array(
    'engine' => 'Apc',
    'duration'=> 9000,
    'probability'=> 100,
    'prefix' => Inflector::slug(APP_DIR) . '_',
));

You can see that the first argument is the string 'default', which I assume means that the default value for all APC caching should use the following array, which includes a duration of 9000 seconds. 您可以看到第一个参数是字符串'default',我假设这意味着所有APC缓存的默认值应使用以下数组,其中包括9000秒的持续时间。 However, in the aforementioned write function, it does a check for the instance's __name variable, which in the case of the cache entries, get set to "_cake_core_", instead of the default string value of "default". 但是,在上述写入函数中,它检查实例的__name变量,在高速缓存条目的情况下,将其设置为“_cake_core_”,而不是默认字符串值“default”。 Shortly after, it goes to the config settings and looks for a value of "_cake_core_". 不久之后,它进入配置设置并查找值“_cake_core_”。 Because this shouldn't be found (as I didn't set it explicitly), or if there was some value set by Cake it would be overridden by my default value (by my definition of default) it would rely on what I've set above. 因为不应该找到它(因为我没有明确地设置它),或者如果Cake设置了一些值,它将被我的默认值覆盖(根据我的默认定义)它将依赖于我所拥有的设置如上。 However, this isn't the case at all. 但事实并非如此。 In the __loadBoostrap function of cake/libs/configure.php: 在cake / libs / configure.php的__loadBoostrap函数中:

if (Configure::read() >= 1) {
    $duration = '+10 seconds';
} else {
    $duration = '+999 days';
}

if (Cache::config('_cake_core_') === false) {
    Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
        'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
        'serialize' => true, 'duration' => $duration
    )));
}

So, if debug is set to 0 (which is what Configure::read() returns when it's not passed anything) and the config string is '_cake_core_' (like it is with my cache entries) it sets $duration to '+999 days', instead of the value I pass. 因此,如果debug设置为0(这是在没有传递任何内容时Configure :: read()返回的内容),并且配置字符串是'_ cake_core_'(就像它与我的缓存条目一样),它将$ duration设置为'+999天',而不是我通过的价值。 The solution is to create another few lines in core.php like so: 解决方案是在core.php中创建另外几行,如下所示:

Cache::config('_cake_core_', array(
    'engine' => 'Apc',
    'duration'=> 9000,
    'probability'=> 100,
    'prefix' => Inflector::slug(APP_DIR) . '_',
));

which overrides Cake's "default" or hard-coded value of 10 seconds or 999 days, depending on the debug value. 它会覆盖Cake的“默认”或10秒或999天的硬编码值,具体取决于调试值。

The first suggestion is probably the simplest: switch to Zend Optimizer (is built-in in 5.5). 第一个建议可能是最简单的:切换到Zend Optimizer (内置于5.5)。

The second suggestion is... have you checked the default settings? 第二个建议是......你检查了默认设置吗? Typically found in /etc/php.d/apc.ini These could override settings by Cake (not used Cake so not sure but I know APC settings are config level). 通常在/etc/php.d/apc.ini中找到它们可以覆盖Cake的设置(不使用Cake,所以不确定,但我知道APC设置是配置级别)。

The user cache entry ttl that you are talking about is not set by the ttl that you have set. 您正在讨论的用户缓存条目ttl不是由您设置的ttl设置的。 It's set by apc.rfc1867-ttl. 它由apc.rfc1867-ttl设置。

Look it here: http://www.php.net/manual/en/apc.configuration.php#ini.apc.rfc1867-ttl 请看这里: http//www.php.net/manual/en/apc.configuration.php#ini.apc.rfc1867-ttl

It's the life time of the file that users can upload. 这是用户可以上传的文件的生命周期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM