分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

php使用memcache存储session

发布时间:2023-09-06 02:08责任编辑:赖小花关键词:暂无标签
安装完php的时候需要安装memcache的扩展

wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz

tar zxf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure --prefix=/usr/local
make && make install

wget http://pecl.php.net/get/memcache-3.0.8.tgz

tar zxf memcache-3.0.8.tgz
cd memcache-3.0.8
locate phpize
/usr/local/php/bin/phpize
locate php-config
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

安装完扩展之后会出现一个路径

/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

定位php.ini的位置

[root@haha-42-12 memcache-3.0.8]# locate php.ini
/etc/puppet/modules/php/files/etc/php.ini
/usr/local/php/etc/php.ini
[root@haha-42-12 memcache-3.0.8]# cat /usr/local/php/etc/php.ini|grep extension

修改如下配置

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"
extension = memcache.so

编辑测试文件

[root@haha-42-12 default]# cat test.php
<?php
$ip = ‘192.168.42.8‘;
$port = 11211;
ini_set("session.save_handler", "memcache");
ini_set("session.save_path", "tcp://$ip:$port");
session_start();
$_SESSION[‘time‘] = time();
?
print ‘time:‘ . $_SESSION[‘time‘];
print "<br>";
$key = session_id();
print ‘session_id:‘ . $key;
print "<br>";
$memcache = new Memcache;
$memcache->addServer($ip, $port);
echo "ke: $key value:" . $memcache -> get($key);
?>
[root@haha-42-12 default]#

通过浏览器进行测试访问

php使用memcache存储session

原文地址:http://blog.51cto.com/jiandan/2155874

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved