`
buliedian
  • 浏览: 1238009 次
  • 性别: 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的Session和Request Handler组件 #### Session组件概览 在CakePHP框架中,Session组件被设计用于管理用户的会话数据,确保网站能够识别并处理特定用户的状态。这在用户登录、购物车功能、个性化...

    memcache简介、安装 and in cakephp

    在CakePHP中使用Memcache,你需要: 1. **配置Cache引擎**:在`config/app.php`文件中配置Cache引擎为'Memcached'。 ```php 'Cache' => [ 'default' => [ 'engine' => 'Memcached', 'host' => '127.0.0.1', /...

    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.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 ...

    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提供了三种...

    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-1.2 manual

    《CakePHP 1.2 手册》是针对该版本框架的重要参考资料,旨在帮助开发者深入理解和有效使用 CakePHP 进行Web开发。 CakePHP 是一个基于Model-View-Controller(MVC)架构模式的开源PHP框架,它简化了Web应用程序的...

    cakephp框架源码

    此外,CakePHP的关联(Association)功能支持模型间的多种关系,如BelongsTo、HasOne、HasMany、BelongsToMany等。 View层,CakePHP使用模板引擎处理视图渲染,通过Helper类提供各种辅助函数,简化HTML的生成。例如...

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

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

    cakephp 框架书籍 英文版

    ### CakePHP框架书籍知识点概述 #### 一、Getting Started(开始使用) - **博客教程**:本书籍通过一个博客项目的示例,引导读者逐步了解CakePHP框架的基本用法。这包括了如何设置环境、创建模型(Model)、控制器...

Global site tag (gtag.js) - Google Analytics