Valkasar
Valkasar

Reputation: 21

How to store PHP Sessions in MYSQL database

Greetings, I need a php class or a list of functions for session_set_save_handler()

There are too many visitors, so the fastest code is needed.

P.S. I can't use Memcached because it isn't installed on my hosting

Upvotes: 2

Views: 4829

Answers (2)

ThiefMaster
ThiefMaster

Reputation: 318488

People here are most likely not going to write a full MySQL session handler for you. But it might not be the best solution anyway:

You need something really fast? Then the answer is Memcached. Another solution would be storing data client-side in signed cookies. The cryptographic signature ensures the user cannot tamper with the cookie data. But that would still increase the bandwidth needed of course.


For the memcached solution, simply install the memcached extension from PECL and then enable the memcached session handler in your code:

ini_set('session.save_handler', 'memcache');
ini_set('session.save_path', '...');

See e.g. http://www.ducea.com/2009/06/02/php-sessions-in-memcached/ for what do use as the "save path".

Upvotes: 2

Timothy
Timothy

Reputation: 21

If your looking for a lot of speed and have actual access to hardware then you might want to look at in memory caching. Memcached has came quite away and you can use it for sessions.

Upvotes: 0

Related Questions