除了檔案的方式之外,ADOdb for PHP 也提供使用資料庫的作法,這樣不但可以加快速度,也可以作分散式的處理。但若是資料庫本身 Loading 重的時候,可能會影響到效能。
所以以下介紹另一種選擇,memcached。就是利用 RAM 當作 session 存放的地方。所有的 session 資料都存放在 RAM 中,這樣存取速度就夠快了吧,而且支援 TCP ,可以很容易的就讓多個 Web Server 使用喔!
yum -y install php-pecl-memcached memcached memcached-devel
# wget http://memcached.googlecode.com/files/memcached-1.4.9.tar.gz # wget https://github.com/downloads/libevent/libevent/libevent-2.0.15-stable.tar.gz --no-check-certificate # tar -zxvf libevent-2.0.15-stable.tar.gz # cd libevent-2.0.15-stable # ./configure # make # make install # cd memcached-1.4.9 # ./configure # make # make install // make a soft link of the libevent # ln -s /usr/local/lib/libevent-2.0.so.5 /lib64/libevent-2.0.so.5
[Session] ; Handler used to store/retrieve data. #session.save_handler = files session.save_handler = memcache ; where MODE is the octal representation of the mode. Note that this ; does not overwrite the process's umask. #session.save_path = "/var/lib/php/session" session.save_path="tcp://localhost:11211"