安装完php的时候需要安装memcache的扩展
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的位置
[[email protected] memcache-3.0.8]# locate php.ini
/etc/puppet/modules/php/files/etc/php.ini
/usr/local/php/etc/php.ini
[[email protected] 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
编辑测试文件
[[email protected] 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);
?>
[[email protected] default]#
通过浏览器进行测试访问
原文地址:http://blog.51cto.com/jiandan/2155874