memcached for PHP session data

Perrin Harkins perrin at elem.com
Mon Dec 5 14:18:08 UTC 2005


On Mon, 2005-12-05 at 08:48 -0500, Denis Antipov wrote:
> We have only one memcache server and it has enough memory to support
> all cache.

That is odd behavior then.  There may be a bug in your PHP code or in
memcached somewhere.  I'd suggest switching over to using a database-
backed sessions and seeing if the problem goes away.

> However, it appearrs that some new cache entries get overwritten

I assume that what you mean here is that some cache entries get removed
from the cache after a while, not that they get overwritten with new
values.  Have you checked for bugs in your expiration time settings?
Are you sure that the values were stored in the cache at all?

> I'm considering backing memcache with MySQL db, however, if it's not
> so efficient with memory, I wouldn't want to overuse the db link and
> the slowness of the database compared with cache.

The common approach to handle this is a write-through cache: all reads
are from the cache, and then the database if nothing is found in the
cache.  All writes go to both.  If you are mostly doing reads, you will
be pulling from the cache.

Keep in mind, MySQL is pretty lightweight as well, and if you have a
small enough site that you only need to run one memcached server, you
can probably host your sessions in MySQL without a noticeable change in
performance.

- Perrin



More information about the memcached mailing list