Search code examples
phpsessiongarbage-collectionsession-timeout

Override garbage collector for manual php session deletion


I want to basically stop garbage collector from deleting my php sessions so that I can manually delete them myself under conditions. How would I go about stopping garbage collector?


Solution

  • In the INI set

    session.gc_probability = 0
    

    This can also be done with ini_set() but make sure you do it with every session_start() call.

    Also, it's worth noting that several Linux distros have this as the default and there is a cron job cleaning up expired sessions.