PHP-FPM save sessions in memcached

8,080

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:
8,080

Related videos on Youtube

Nishanth
Author by

Nishanth

Updated on September 18, 2022

Comments

  • Nishanth
    Nishanth almost 2 years

    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?

    • Guntis
      Guntis about 9 years
      If You do not plan to run memcached in cluster, then I suggest to store sessions in ram (tmpfs). usually /dev/shm
    • Nishanth
      Nishanth about 9 years
      @Guntis that's a great idea too. But I don't like the session garbage collection via cronjobs in php.
    • r_3
      r_3 about 9 years
      @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
    • Nishanth
      Nishanth about 9 years
      @r_3 memcached does gc using TTL. I use HHVM now which deals yet differently with sessions.
    • r_3
      r_3 about 9 years
      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.
  • alexus
    alexus over 9 years
    for TCP, use following: session.save_path='tcp://127.0.0.1:11211, tcp://192.168.1.2:11211'
  • t1gor
    t1gor about 9 years
    Guys, is it actually secure to do that? Memcached doesn't have any auth in front of it.
  • Nishanth
    Nishanth about 9 years
    Memcached is secured through the network layer or when you deploy it via unix socket, no other server can access it.