Memcached for Php sessions on CentOS 6

Today I decided to try out  memcached for php sessions instead of files.

Memcached is a server, that runs on port 11211 (by default). By installing a Php extensions and configuring php.ini you can save session data in RAM instead of on disk. 

First, you will need to grab some dependencies:

yum install memcached php-pecl-memcached phpMemcachedAdmin

You will need the EPEL repo to install the php extension and the option web interface to memcached.

Start up memcached and enable on boot:

service memcached start
chkconfig memcached on

Give yourself access to phpMemcachedAdmin by editing /etc/httpd/conf.d/phpMemcachedAdmin.conf:

<IfModule !mod_authz_core.c>
    # Apache 2.2
    Order Deny,Allow
    Deny from All 
    Allow from 127.0.0.1
    Allow from <YOUR IP HERE>
    Allow from ::1 
 </IfModule>

You can access the interface at http://<SERVER IP>/phpMemcachedAdmin

Update the following in php.ini:

session.save_handler = memcached
session.save_path = "127.0.0.1:11211"

Restart apache and you should be all set

service httpd restart

Watch the phpMemcachedAdmin interface as your application starts using sessions.

Now to run some benchmarks and see if I get any performance gains, if not than at least I could use memcached to host sessions for multiple app servers.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: