无法在 CakePHP 中使用 Apc 缓存 shell
Unable to use Apc cache within CakePHP shell
所以我在尝试 运行 shell 脚本时遇到了这个著名的错误(通过浏览器运行没有问题)
Fatal error: Uncaught CacheException: Cache engine "default" is not
properly configured.
默认指向 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
包含 /cache
、tmp/cache/models
、tmp/cache/persistent
和 tmp/logs
,其权限与 tmp
.
相同
例如,如果我将默认引擎从 Apc
更改为 Redis
,则一切正常。
Apc
for php7.0
已弃用,因此您需要安装 apcu
而不是 apcu-bc
- 为了与 apc
.
兼容
也许只是我的情况,但是当我输入 .../cli/php.ini
那些行时
extension=apcu.so
extension=apc.so
apcu.enabled=1
apc.enable_cli=1
Apc 仍然无法工作,我收到警告:
default cache was unable to write 'key' to Apc cache
当我创建两个文件时它开始工作
.../cli/config.d/apcu.ini
其中包含:
extension=apcu.so
和 .../cli/config.d/z_apc.ini
其中包含:
extension=apc.so
apc.enable_cli=1
(z
前缀为顺序,apc要在apcu之后加载)
所以我在尝试 运行 shell 脚本时遇到了这个著名的错误(通过浏览器运行没有问题)
Fatal error: Uncaught CacheException: Cache engine "default" is not properly configured.
默认指向 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
包含 /cache
、tmp/cache/models
、tmp/cache/persistent
和 tmp/logs
,其权限与 tmp
.
例如,如果我将默认引擎从 Apc
更改为 Redis
,则一切正常。
Apc
for php7.0
已弃用,因此您需要安装 apcu
而不是 apcu-bc
- 为了与 apc
.
也许只是我的情况,但是当我输入 .../cli/php.ini
那些行时
extension=apcu.so
extension=apc.so
apcu.enabled=1
apc.enable_cli=1
Apc 仍然无法工作,我收到警告:
default cache was unable to write 'key' to Apc cache
当我创建两个文件时它开始工作
.../cli/config.d/apcu.ini
其中包含:
extension=apcu.so
和 .../cli/config.d/z_apc.ini
其中包含:
extension=apc.so
apc.enable_cli=1
(z
前缀为顺序,apc要在apcu之后加载)