Home > php教程 > php手册 > 采用memcache在web集群中实现session的同步会话

采用memcache在web集群中实现session的同步会话

WBOY
Release: 2016-06-06 20:20:31
Original
1264 people have browsed it

这篇文章主要介绍了采用memcache在web集群中实现session的同步会话,需要的朋友可以参考下

使用memcache来同步session是还是不错的,当然也可以通过redis来保存session,可以php开启并将Session存储到Redis缓存,下面是设置利用memcache在web集群中同步会话session的实现过程:

1、模拟web集群

我启动了二个memcached进程,,分别模拟二台服务器

/usr/local/bin/memcached -d -m 20 -u zhangy -p 12000 -P ./memcached.pid
/usr/local/bin/memcached -d -m 20 -u zhangy -p 13000 -P ./mem.pid

2、修改php的配置

vi /usr/local/php/lib/php.ini

session.save_handler = "memcache"
memcache.hash_strategy = "consistent"
session.save_path = "tcp://127.0.0.1:13000?weight=10,tcp://127.0.0.1:12000"

说明:第一行,session的储存方式是memcache;第二行,memcache的hash算法是consistent;第三行,session储存的地位;

3、重启apache

查看phpinfo

session

Session Support enabled

Registered save handlers files user sqlite memcache

Registered serializer handlers php php_binary

紧接着下面是:

session.save_path tcp://127.0.0.1:13000,tcp://127.0.0.1:12000 tcp://127.0.0.1:13000,tcp://127.0.0.1:12000

4、做个简单测试如下:

a)、准备文件session.php

b)、显示session内容文件

addServer("127.0.0.1",12000)or die ("Could not add server 12000"); $mem->addServer("127.0.0.1",13000)or die ("Could not add server 13000"); $val = $mem->get('qp0mrob2ovcqle3u4lbr4obsa5'); //echo session_id(); 得到的session id echo $val; ?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template