码迷,mamicode.com
首页 > Web开发 > 详细

memcached结合php

时间:2016-04-29 23:25:02      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

//安装php的memcache扩展

一、使用php自带的pecl安装程序
[root@localhost src]# /usr/local/php/bin/pecl install memcache
...
...
...
Build process completed successfully
Installing /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so
install ok: channel://pecl.php.net/memcache-2.2.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcache.so" to php.ini

[root@localhost src]# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so /usr/local/php/ext
[root@localhost src]# vim /usr/local/php/etc/php.ini
...
...
;extension_dir = "./"     
/*改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"*/
//再添加一行
extension = "memcache.so“

//检验,查看是否有memcache
[root@localhost src]# /usr/local/php/bin/php -m   

//检测php是否连接memcache,下载一个已经写好的脚本
[root@localhost src]# curl www.apelearn.com/study_v2/.memcache.txt >1.php 2>/dev/null

//执行
[root@localhost src]# /usr/local/php/bin/php 1.php
//执行成功-- 只有当在php.ini中定义了memcache模块才可以执行此脚本
Get key1 value: This is first value<br>Get key1 value: This is replace value<br>Get key2 value: Array
(
    [0] => aaa
    [1] => bbb
    [2] => ccc
    [3] => ddd
)
<br>Get key1 value: <br>Get key2 value: <br>

 

//memcached实现session共享

一、不管在哪种架构中,都能实现的
[root@localhost ~]# vim /usr/local/php/etc/php.ini
//添加
session.save_handler = "memcache"
session.save_path = "tcp://127.0.0.1:11211"  
//如果memcached服务为远程机器,则可将ip改为远程机器的ip

//测试
[root@localhost src]# wget http://study.lishiming.net/.mem_se.txt
[root@localhost src]# mv .mem_se.txt /usr/local/apache2/htdocs/session.php            //因为我们要用curl或浏览器访问此脚本,所以要保证其可以被打开
[root@localhost src]# curl localhost/session.php
//查看是否有显示内容,如果没有,查看已经配置好的网站文件test.conf

 

//--!!如果添加到php.ini不成功,可以添加到apache或nginx对应的php-fpm的配置文件中,见下方配置

//
在httpd.conf或者test.conf对应的虚拟主机中的配置语句{LAMP结构} php_value session.save_handler "memcache" php_value session.save_path "tcp://127.0.0.1:11211"

//在php-fpm.conf中的pool中添加 {LNMP结构}
php_value[session.save_handler] = memcache
php_value[session.save_path] = "tcp://127.0.0.1:11211

 

memcached结合php

标签:

原文地址:http://www.cnblogs.com/frankielf0921/p/5409489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!