首先,在运行PHP 5.3.15的Macbook Pro dev服务器上使用PECL(并验证其工作)成功安装了Memcache和APC
我刚刚发布了一个测试Cake 2.2.2应用程序。在Config/core.php
我有以下内容:
/**
* Pick the caching engine to use. If APC is enabled use it.
* If running via cli - apc is disabled by default. ensure it's available and enabled in this case
*
*/
$engine = 'File';
if (extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) {
$engine = 'Apc';
}
if (extension_loaded('memcache') && php_sapi_name() !== 'cli') {
$engine = 'Memcache';
}
// In development mode, caches should expire quickly.
$duration = '+999 days';
if (Configure::read('debug') >= 1) {
$duration = '+10 seconds';
}
// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
$prefix = 'mcmyapp_';
/**
* Configure the cache used for general framework caching. Path information,
* object listings, and translation cache files are stored with this configuration.
*/
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
/**
* Configure the cache for model and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections.
*/
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
Cache::config('default', array(
'engine' => $engine,
'serialize' => ($engine === 'File'),
'duration'=>$duration,
'prefix'=>$prefix,
));
debug(Cache::settings());
上述最终debug()的输出是:
array(
'prefix' => '*****',
'engine' => 'Memcache',
'serialize' => false,
'duration' => (int) 10,
'servers' => array(
(int) 0 => '127.0.0.1'
),
'compress' => false,
'persistent' => true,
'probability' => (int) 100,
'groups' => array()
)
所以在core.php
中,似乎Cake想要使用Memcache作为其缓存引擎。
然而,当我在浏览器中访问localhost/myapp/pages/home
时,CakePHP默认的新鲜出炉的欢迎页面迎接我,告诉我The FileEngine is being used for core caching
我的应用中的其他任何地方(core.php
除外)如果我debug(Cache::settings())
,我会收到以下信息:
array(
'prefix' => '*****',
'engine' => 'File',
'serialize' => false,
'duration' => (int) 10,
'servers' => array(
(int) 0 => '127.0.0.1'
),
'compress' => false,
'persistent' => true,
'probability' => (int) 100,
'groups' => array()
)
基本上,CakePHP似乎恢复为File进行缓存,忽略我在core.php
中的配置以使用Memcache ......除非我在这里做错了什么??!
我已经使用Configure::write('debug', 0)
和Configure::write('debug', 1)
尝试了此操作。
我应该提一下,在上面,php.ini
启用了APC和Memcache扩展。
如果提前感谢,我们将非常感谢您的帮助。
答案 0 :(得分:1)
Memcached应该在某个端口上,默认值为11211(检查)...所以你的配置尝试连接到Memcached,失败并恢复到默认(文件)缓存......
尝试:
Cache::config('default', array(
'engine' => 'Memcache',
'duration'=> 3600,
'probability'=> 100,
'servers' => array('127.0.0.1:11211') <<<<==
));