`
buliedian
  • 浏览: 1197414 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

[CakePHP]How to use Session in conjunction with Memcache

阅读更多

Cakephp default session is saved in the configuration /etc/php.ini,

this was defined in app/config/core.php:

Configure::write('Session.save', 'php');

most likely it looks as below:

session.save_handler = files
session.save_path = "/var/lib/php/session"

this kind of file based session/cache will not work correctly under load balancer/multi web app servers.

the solution is using database or Memcache.

For using Memcache, we should change the config to:

Configure::write('Session.save', 'cache');

and enable the Memcache engine in core.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]
'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
));

we can check if the memcache has been installed and running by phpinfo() and ps -ef|grep memcache

but unfortunately, even you installed/configured memcache and cakephp well both, this will still not work.

you will lose sessions when navigating pages.

if you enable debug mode, you will see errors in the bottom of the page:

Fatal error: Class 'Debugger' not found in /var/www/cake/libs/debugger.php on line 252 Warning: Invalid callback CakeSession::__close, class 'CakeSession' not found in Unknown on line 0

to solve this problem, you have to apply below patch:

http://cakephp.lighthouseapp.com/projects/42648/tickets/825-debuggerphp-error-when-session-set-to-cache

--- public_html/cake/libs/model/datasources/datasource.php.orig	2010-11-09 15:56:06.897482341 -0600
+++ public_html/cake/libs/model/datasources/datasource.php 2010-11-09 15:57:10.341327526 -0600
@@ -521,6 +521,12 @@ class DataSource extends Object {
$this->rollback($null);
}
if ($this->connected) {
+ if ((Configure::read('Session.save') == 'cache' ||
+ Configure::read('Session.save') == 'database')
+ && function_exists('session_write_close')) {
+ session_write_close();
+ }
+
$this->close();
}
}
分享到:
评论

相关推荐

    cakephp--使用_CakePHP_的_Session_和_Request_Handler_组件

    cakephp--使用_CakePHP_的_Session_和_Request_Handler_组件

    memcache简介、安装 and in cakephp

    没分了,下载不了。挣点分。 有三个文件,分别为: memcache简介、安装 and in cakephp。

    Learn CakePHP: With Unit Testing, 2nd Edition

    You'll learn about unit testing and how to implement it in CakePHP. This approach to coding leads to better code, better applications, and better programming habits. With this knowledge your ...

    Learn CakePHP(Apress,2ed,2016)

    You’ll learn about unit testing and how to implement it in CakePHP. This approach to coding leads to better code, better applications, and better programming habits. With this knowledge your ...

    Beginning CakePHP:From Novice to Professional

    Target beginners of CakePHP or web frameworks in general as well as experienced developers with limited exposure to CakePHP. A secondary audience may include developers undecided on adopting CakePHP ...

    Learn.CakePHP.With.Unit.Testing.1484212134

    You'll learn about unit testing and how to implement it in CakePHP. This approach to coding leads to better code, better applications, and better programming habits. With this knowledge your ...

    CakePHP 1.3 Application Development Cookbook.pdf

    afterFind) in behaviors, while the fourth recipe shows how to use behaviors to add additional field values when a save operation is being undertaken. The last two recipes in this chapter give ...

    Building PHP Applications with Symfony, CakePHP, and Zend Framework.pdf.rar

    解压密码在:http://www.pin5i.com/showtopic-building-php-applications-with-symfony-cakephp-zend-framework.html

    CakePHP 2 Application Cookbook

    From routing to authentication, the model layer and the events system, as well as views and unit testing, you'll learn how to handle the ins and outs of developments using CakePHP. With fast paced ...

    cakephp php-framework

    There are two main ways to get a fresh copy of CakePHP. You can either download an archive copy (zip/tar.gz/tar.bz2) from the main website, or check out the code from the git repository. To download ...

    CakePHP框架Session设置方法分析

    本文实例讲述了CakePHP框架Session设置方法。分享给大家供大家参考,具体如下: CakePHP Session 存储选项 CakePHP提供给用户了3种Session数据保存方式: 1. CakePHP安装目下的临时文件; 2. 采用PHP的默认机制; 3. ...

    CakePHP php框架 v3.7.0 beta1.zip

    在cakephp.org站点的Sites in the wild页面可以看到当前使用CakePHP框架的网站列表。 CakePHP 是一个运用了诸如ActiveRecord、Association Data Mapping、Front Controller和MVC等著名设计模式的快速开发框架。该...

    CakePHP php框架 v3.8.5

    在cakephp.org站点的Sites in the wild页面可以看到当前使用CakePHP框架的网站列表。CakePHP 是一个运用了诸如ActiveRecord、Association Data Mapping、Front Controller和MVC等著名设计模式的快速开发框架。该项目...

    CakePHP php框架 v3.7.8.zip

    在cakephp.org站点的Sites in the wild页面可以看到当前使用CakePHP框架的网站列表。 CakePHP 是一个运用了诸如ActiveRecord、Association Data Mapping、Front Controller和MVC等著名设计模式的快速开发框架。该...

    PHP的框架之CakePHP-CakePHP教程

    打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...

    RedisSession:CakePHP Redis会话存储

    Cakephp 2.x的Redis会话数据源-Croogo 1.5 一个简单的Redis会话存储,具有额外的功能,可以保留已登录用户的“映射”。 然后,身份验证对象可以使用此映射来防止同一用户的多次登录。 要求: wddx模块已激活cakephp>...

    cakephp 框架

    cakephp 框架 cakephp 框架 cakephp 框架 cakephp 框架 cakephp 框架

    PHP的框架之CakePHP-CakePHP教程终极教程

    打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...

    Packt.Publishing.CakePHP.Application.Development.Jun.2008

    As the first book to come out on CakePHP, there was a lot of pressure on this title to be really strong. On the whole, it has pretty good coverage of the topic, but the flow of the title is undermined...

    CakePHP 3.4 开发手册文档 CakePHP Cookbook Documentation Release 3.4

    CakePHP 3.4 开发手册文档 CakePHP Cookbook Documentation Release 3.4

Global site tag (gtag.js) - Google Analytics