Php – memcached and PHP … massive lag with sessions

memcachedPHP

I'm working on a new server built with Unbuntu 10.04, running php-fastcgi, nginx, and memcached.

phpinfo() script loads and works great, same as a test memcached script. For any script using sessions, page load time rockets through the roof.

--- memcached.ini ---
extension=memcached.so
memcache.hash_strategy = "consistent"
memcache.max_failover_attempts = 100
memcache.allow_failover = 1
session.save_handler = memcached
session.save_path = "tcp://127.0.0.1:11211?persistent=1&weight=1&timeout=1&retry_interval=15"

Let me know if you need to see any other configs.

Best Answer

The problem is in the session.save_path syntax between memcache.so and memcached.so:

extension=memcache.so
session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211"

vs.

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

Note the protocol in the memcache one, no protocol in the memcached one.

Also, make sure you actually have the .so you are trying to load. They're two separate packages via apt-get or yum or whatever flavor you use.

Any breakage due to loading the wrong module or using incorrect syntax causes a 30 second load delay in php while it tries to use your session mechanism and eventually times out.

Hope that saves someone some time. ;-)