session variables - memcache vs. database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mottwsc
Forum Commoner
Posts: 55
Joined: Sun Dec 23, 2007 8:01 pm

session variables - memcache vs. database

Post by mottwsc »

I have different operations spread across multiple servers for a LAMP application. I need a way for session data to be accessed across these multiple servers. Using a database table to store session data was the first thought, but then someone suggested using memcache/memcached because it will be cleaner (since it is self-cleaning). I want to use PHP's built-in session handling, but want to direct it elsewhere in terms of where it is stored.

I have two questions:

Is there a strightforward example which shows how to use PHP's built-in session handling but with the use of memcache?

Is there any reason I would use a database table instead of memcache?

Thanks!
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: session variables - memcache vs. database

Post by Darhazer »

Change settings in your php.ini:

Code: Select all

session.save_handler = memcache
; change server:port to fit your needs...
session.save_path="tcp://server:port?persistent=1&weight=1&timeout=1&retry_interval=15
* found on Google, never used it
mottwsc
Forum Commoner
Posts: 55
Joined: Sun Dec 23, 2007 8:01 pm

Re: session variables - memcache vs. database

Post by mottwsc »

thanks for the suggestion - I'll try that
Post Reply