无法在CakePHP shell中使用Apc缓存

时间:2017-02-09 09:38:30

标签: php shell cakephp caching cakephp-2.0

所以我在尝试运行shell脚本时遇到这个着名的错误(通过浏览器工作没有问题)

  

致命错误:未捕获的CacheException:缓存引擎“默认”不是   正确配置。

默认指向Apc缓存。

Cache::config('default', array(
    'engine' => 'Apc',
    'prefix' => 'some_default',
    'duration' => '+1 hour'
));

堆栈追踪:

#0 /.../lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('default')
#1 /.../app/Config/core.php(381): Cache::config('default', Array)
#2 /.../lib/Cake/Core/Configure.php(72): include('/home/...')
#3 /.../lib/Cake/bootstrap.php(432): Configure::bootstrap(true)
#4 /.../lib/Cake/Console/ShellDispatcher.php(145): require('/home/...')
#5 /.../lib/Cake/Console/ShellDispatcher.php(100): ShellDispatcher->_bootstrap()
#6 /.../lib/Cake/Console/ShellDispatcher.php(54): ShellDispatcher->_initEnvironment()
#7 /home/ in /.../lib/Cake/Cache/Cache.php on line 186

环境:

Apache/2.4.18 (Ubuntu)
PHP 7.0.13-0ubuntu0.16.04.1 (cli)
CakePHP v2.8.0

php -i | grep apc:

apc.coredump_unmap => Off => Off
apc.enable_cli => On => On
apc.enabled => On => On
apc.entries_hint => 4096 => 4096
apc.gc_ttl => 3600 => 3600
apc.mmap_file_mask => no value => no value
apc.preload_path => no value => no value
apc.serializer => php => php
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.smart => 0 => 0
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.writable => /tmp => /tmp

Cake tmp文件夹 - 777用户拥有的权限www-data(也运行apache) tmp包含/cachetmp/cache/modelstmp/cache/persistenttmp/logs,其权限与tmp相同。

例如,如果我将默认引擎从Apc更改为Redis,那么一切都可以正常运行。

1 个答案:

答案 0 :(得分:0)

{P} Apc已弃用php7.0,因此您需要安装apcu而不是apcu-bc - 才能与apc兼容。

也许只是在我的情况下,但是当我放入.../cli/php.ini那些行

extension=apcu.so
extension=apc.so

apcu.enabled=1
apc.enable_cli=1

Apc仍无法正常工作,我收到了警告:

  

默认缓存无法将“密钥”写入Apc缓存

当我创建两个文件时它开始工作

.../cli/config.d/apcu.ini包含:

extension=apcu.so

.../cli/config.d/z_apc.ini包含:

extension=apc.so
apc.enable_cli=1

z前缀用于命令,apc应在apcu之后加载)