Friday, April 24, 2015

Store PHP sessions in Memcached

Install Memcached:

If Memcached is installed, storing PHP session files in RAM can be much more efficient than storing on disk and can also save some IO. To configure this, you should modify the main php.ini file and change session.save_handler to memcached.

# yum install memcached

# vim /etc/sysconfig/memcached

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1"

# systemctl enable memcached.service

# systemctl restart memcached.service

# memcached-tool 127.0.0.1:11211 stats

# yum install php-pecl-memcached

# vim /etc/php.ini

session.save_handler = memcached

#session.save_path = unix:/tmp/memcached.sock
session.save_path = "127.0.0.1:11211"

# systemctl restart php-fpm.service

# php -r 'echo phpinfo();' | grep memcached

memcached support => enabled
Registered save handlers => files user redis memcached
session.save_handler => memcached => memcached

No comments: