是否建议将PHP会话存储在MemCache中? [英] Is it recommended to store PHP Sessions in MemCache?

查看:58
本文介绍了是否建议将PHP会话存储在MemCache中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在负载均衡器后面使用几个Web服务器,并且可以启用粘滞会话"将用户限制在一个特定的Web服务器上-这将起作用.

I'm working with a couple of Web Servers behind a Load Balancer and I can enable Sticky Sessions to hold a user to the one specific Web Servers - this will work.

我一直在阅读有关PHP Sessions&的信息. MemCache.我必须说我读的书让人有些困惑,因为有些页面说它是个好主意,而另一些页面则相反.

I have been reading about PHP Sessions & MemCache. I must say what I've read is a touch confusing as some pages say its a good idea and others the opposite.

问题:

  1. 是否可以将php会话保留在内存缓存中?
  2. 在记忆快取上使用粘性会话是否更好?
  3. memcache中的php会话有什么问题-注意:我可以获得足够的缓存(amazon使其可扩展).

推荐答案

1:是.我强烈建议将PHP会话存储在Memcached中.原因如下:

Memcached非常适合存储数据库和文件系统经常访问的小数据块.

Memcached is great for storing small chunks of data that are frequently accessed by the database and filesystem.

Memcached专为会话而设计.它最初是livejournal.com首席开发人员的创意,后来又用于缓存用户帖子的内容.好处是立竿见影的:大多数动作是在内存中进行的.页面加载时间大大缩短.

Memcached was designed specifically for sessions. It was originally the brainchild of the lead developer of livejournal.com, and later used to also cache the content of users' posts. The benefit was immediate: most of the action was taking place in memory. Page load times greatly improved.

值得庆幸的是,PHP和Apache具有轻松的实现,可以处理与Memcached的会话.只需安装一些shell命令

Thankfully, PHP and Apache have an easy implementation to handle sessions with Memcached. Simply install with a few shell commands

debian的示例:

example for debian:

sudo apt-get -t stable install php5-memcached

将php.ini设置更改为类似于以下内容的

change your php.ini settings to something similar to:

(摘自 http://www.dotdeb.org/2008/08/25/storing-your-php-sessions-using-memcached/)

 session.save_handler = memcache
 ; change server:port to fit your needs...
 session.save_path="tcp://server:port?persistent=1&weight=1&
timeout=1&retry_interval=15"

关键是session.save_path

The key is the session.save_path

它将不再指向服务器上的相对文件路径. 提到了APC-APC用于缓存程序使用的.php文件. APC和Memcached将显着减少IO,并使Apache可以自由地更快地为资源(例如图像)提供服务.

It will no longer point to a relative file path on your server. APC was mentioned- APC for the caching of .php files used by the program. APC and Memcached will reduce IO signicantly and leave Apache free to serve resources,such as images, faster.

2 :

3: 使用Memcached的根本缺点是数据易变性

会话数据在Memcached中不是持久性的.因此,当服务器崩溃时,内存中的所有数据都会丢失.每个人都必须再次登录.

Session data is not persistent in Memcached. So if and when the server crashes, all data in memory is lost. Everyone will have to log in again.

然后您就会消耗内存...

请记住:会话存储在内存中.如果您的网站可以处理大量并发用户,则可能需要花一些额外的钱来分配更大的内存.

Remember: the sessions are stored in the memory. If your website handles a large amount of concurrent users, you may have to shell out a little extra money for a larger memory allocation.

这篇关于是否建议将PHP会话存储在MemCache中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆