php使用memcache存儲session
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
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
[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");
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