Home  >  Article  >  php教程  >  php将session保存在memcached中的方法

php将session保存在memcached中的方法

WBOY
WBOYOriginal
2016-05-25 16:48:121881browse

session是php中一个服务器端超级全局变量而memcache是缓存应用,下面我来把它们整合起来把session存放在memcache中,下面我们一起来看如何实现的吧。

1.首先安装memcached或者memcache软件

参考:wamp 安装 memcache/memcached详细说明 

2.安装php_memcache.dll扩展

3.设置session保存在memcached

方法一:

修改php.ini文件

session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211"

方法二:

程序中动态设置

ini_set("session.save_handler", "memcache");
ini_set("session.save_path", "tcp://127.0.0.1:11211");

测试程序

1.session.php

2.test.php

<?php
// memcache test code
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect(&#39;127.0.0.1&#39;, 11211) or die("Could not connect"); //连接Memcached服务器
print_r($memcache->get(&#39;5d3d79d7500f5836033e9019b3eefc6f&#39;)); //username|s:9:"phpff.com";
?>


文章链接:

随便收藏,请保留本文地址!

Statement:
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