Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to switch my session_handler to memcached, I'm not sure if it worked, it does not look like it did.

vi /etc/php5/fpm/php.ini

session.save_handler = memcached
session.save_path = unix://run/memcached/memcached.sock

/etc/init.d/php5-fpm restart

After hitting my blog a few times, I should have a key in the memcached, shouldn't I?

nc -U /run/memcached/memcached.sock

giant:~# nc -U /run/memcached/memcached.sock
stats items
END
stats slabs
STAT active_slabs 0
STAT total_malloced 0
END

phpinfo():

session.gc_probability  0   0
session.hash_bits_per_character 5   5
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    memcache    memcache
session.save_path   unix://run/memcached/memcached.sock unix://run/memcached/memcached.sock
session.serialize_handler   php php
session.upload_progress.cleanup On  On
session.upload_progress.enabled On  On
session.upload_progress.freq    1%  1%
session.upload_progress.min_freq    1   1
session.upload_progress.name    PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix  upload_progress_    upload_progress_
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

Can someone lead me to the correct configuration please?

share|improve this question
1  
If You do not plan to run memcached in cluster, then I suggest to store sessions in ram (tmpfs). usually /dev/shm –  Guntis May 22 at 6:10
    
@Guntis that's a great idea too. But I don't like the session garbage collection via cronjobs in php. –  DanFromGermany May 22 at 8:16
    
@DanFromGermany: as opposed to no gc'ing at all when storing sessions in memcached. btw: there is an internal gc-mechanism, the cronjob was introduced for more security on multiuser systems, see bugs.debian.org/cgi-bin/bugreport.cgi?bug=267720 –  r_3 Jun 22 at 12:57
    
@r_3 memcached does gc using TTL. I use HHVM now which deals yet differently with sessions. –  DanFromGermany Jun 22 at 13:25
    
i wouldn't call memcaches lru alg a garbage collector. it's more like taking out the trash only if the dustbin is completely full as compared to when it starts to smell. –  r_3 Jun 22 at 14:06

1 Answer 1

Did not work:

session.save_path = unix://run/memcached/memcached.sock

Did work:

session.save_path = "/run/memcached/memcached.sock"

Quotes added, protocol removed

share|improve this answer
1  
for TCP, use following: session.save_path='tcp://127.0.0.1:11211, tcp://192.168.1.2:11211' –  alexus Feb 17 at 16:23
    
Guys, is it actually secure to do that? Memcached doesn't have any auth in front of it. –  t1gor Apr 28 at 14:00
    
Memcached is secured through the network layer or when you deploy it via unix socket, no other server can access it. –  DanFromGermany May 22 at 8:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.