Store PHP Session in MemCache

By defualt PHP stores the session in file and these setting are defined in php.ini file. It would have two settings for saving the sessions in file.

If you are not sure what is the session save path then you should read this post about Session Save Path in PHP.

Be default it will have below lines in your php.ini file.

session.save_handler = files session.save_path = "/session save path/"
  session.save_handler = files
  session.save_path = "/session save path/"

To save your sessions using memcache you need to change your php.ini lines to below lines. To save your session using memcache you will need below details to get it done.

  1. Memcache Server
  2. Memcache Port

After getting these details you will need to comment above lines and need to place below lines.

session.save_handler = memcache session.save_path="tcp://server:port?persistent=1&weight=1&timeout=1"
  session.save_handler = memcache
  session.save_path="tcp://server:port?persistent=1&weight=1&timeout=1"

After making these changes you will need to restart your web server. Here what we are instructing php to set session handler to memcache and in next line we are defining the save path for session.

You might be surprized Why would you save your PHP sessions in memcache? If you are curious to know what would be the reason then subscribe to our RSS Feed, You will be notified by the email for this answer.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: