21.8 memcached中儲存session
1. 下載session儲存指令碼:[[email protected] ~]# wget http://study.lishiming.net/.mem_se.txt
2. 進入[[email protected] ~]# cd /data/wwwroot/test/
3. 移動session儲存指令碼,並重命名為php格式指令碼:[[email protected] test.com]# mv /root/.mem_se.txt 1.php
4. curl訪問1.php:[[email protected] test.com]# curl localhost/1.php
5. 檢視tmp下有沒有sess_格式的檔案:[[email protected] test.com]# ls -lt /tmp/
6. 編輯php-ini:[[email protected] test.com]# vim /usr/local/php-fpm/etc/php-ini
註釋掉這行:;session.save_handler = files #新增以下:
session.save_handler = memcache session.save_path
"tcp://192.168.0.9:11211"
本例項是在lamp/lnmp環境下實現(下面哪種沒問題,就用哪種)
1. 編輯php.ini新增兩行
session.save_handler = memcache session.save_path
"tcp://192.168.0.9:11211"
2. 或者httpd.conf中對應的虛擬主機中新增
php_value session.save_handler "memcache" php_value session.save_path "tcp://192.168.0.9:11211"
3. 或者php-fpm.conf對應的pool中新增
php_value[session.save_handler] = memcache
php_value[session.save_path] = " tcp://192.168.0.9:11211 "
7. curl訪問1.php:
[[email protected] test.com]# curl localhost/1.php