标签:Memcached
Memcached介绍是国外社区网站LiveJournal团队开发,通过缓存数据库查询结果,减少数据库访问次数,从而提高动态web站点性能。官方站点?http://memcached.org/?
基于c/s架构,协议简单
基于libevent的事件处理
自主内存存储处理(slab allowcation)
数据过期方式:Lazy Expiration 和?LRU
先安装php的memcache扩展
# wget http://www.lishiming.net/data/attachment/forum/memcache-2.2.3.tgz
# tar zxf memcache-2.2.3.tgz
# cd memcache-2.2.3
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装完后会有类似这样的提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
memcache.so opcache.a opcache.so redis.so
把这个记住,然后修改php.ini,把 extension_dir = "./" 修改为extension_dir = "/usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20090626/"
并添加一行
extension="memcache.so"
/usr/local/php/bin/php -m |grep memcache
下载测试php脚本
curl www.apelearn.com/study_v2/.memcache.txt > 1.php 2>/dev/null
/usr/local/php/bin/php 1.php
本实例是在lamp/lnmp环境下实现
编辑php.ini添加两行
session.save_handler = memcache
session.save_path = "tcp://192.168.0.9:11211"?
或者httpd.conf中对应的虚拟主机中添加
php_value session.save_handler "memcache"
php_value session.save_path "tcp://192.168.0.9:11211"?
或者php-fpm.conf对应的pool中添加
php_value[session.save_handler] = memcache
php_value[session.save_path] = " tcp://192.168.0.9:11211 "
wget http://study.lishiming.net/.mem_se.txt
mv .mem_se.txt /usr/local/apache2/htdocs/session.php
curl localhost/session.php
类似于1443702394<br><br>1443702394<br><br>i44nunao0g3o7vf2su0hnc5440
telnet 127.0.0.1 11211
get i44nunao0g3o7vf2su0hnc5440
标签:Memcached
原文地址:http://blog.51cto.com/chenshengsheng/2115358