cakephp - 使用memcache进行会话

时间:2011-11-01 15:22:30

标签: cakephp memcached

我对cakephp很新,我无法将其配置为在我的实时服务器上运行。它在我的本地机器上运行良好。

我认为问题是我的live服务器配置为使用Memcache。当我访问现场网站时,我得到了:

Warning (2): session_start() [function.session-start]: open(=1&retry;_interval=15/sess_mt8tpui04vorqojg7s945e5sf5, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Model/Datasource/CakeSession.php, line 615]
Warning (2): session_write_close() [function.session-write-close]: open(=1&retry;_interval=15/sess_mt8tpui04vorqojg7s945e5sf5, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Controller/Controller.php, line 712]
Warning (2): session_write_close() [function.session-write-close]: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (tcp://127.0.0.1:11211?persistent=1&weight;=1&timeout;=1&retry;_interval=15) [CORE/Cake/Controller/Controller.php, line 712]

所以我尝试通过将以下内容添加到app / Config / core.php来启用cake来使用memcache:

Cache::config('default', array(
    'engine' => 'Memcache'
));

但我仍然得到同样的错误。

php.ini配置为正确使用memcache。

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:4)

你的Cache :: config看起来不完整!

它看起来应该是这样的,这个代码块将在app / Config / bootstrap.php中

Cache::config('default', array(
          'engine' => 'Memcache', //[required]
          'duration' => 3600, //[optional]
          'probability' => 100, //[optional]
          'prefix' => Inflector::slug(APP_DIR) . '_', //[optional]  prefix every cache file with this string
          'servers' => array(
                  '127.0.0.1:11211' // localhost, default port 11211
          ), //[optional]
          'persistent' => true, // [optional] set this to false for non-persistent connections
          'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
  ));

您还需要设置会话处理程序http://book.cakephp.org/2.0/en/development/sessions.html#cache-sessions

我看起来像这样,请注意我称之为“会话” &安培;此代码块将位于app / Config / core.php

Configure::write('Session', array(
        'defaults' => 'cache',
            'handler' => array(
                'config' => 'sessiones'
            ),
        'cookie' => 'PHPSESSID',
        'timeout' => 3600,
        'cookieTimeout' => 0,
        'autoRegenerate' => false,
        'checkAgent' => true,
        'ini' => array(
            'session.cookie_secure' => false,
            'session.cookie_httponly' => true,
        )
    ));

然后为处理程序“会话”设置Cache:config  此代码块将位于app / Config / bootstrap.php

Cache::config('sessiones', array('engine' => 'Memcache','duration'=> 3600,/*'prefix' =>'es',*/ 'servers' => array(array('127.0.0.1:11211'), 'compress' => false));