6

PHP has several session settings that control the probability that garbage collection (i.e. deletion of expired sessions) will occur.

My question is: does this probability apply to all running Apache threads on all virtualhosts on any given Apache server?

For example:

  • If the probability is set to 1/100, does that mean that any Apache thread that runs a PHP process goes into the pool of processes that may have gc run?
  • or, does that apply only to the threads runnning for any given VirtualHost? Or other sort of partitioning?
  • Finally, if a PHP process that triggers gc, does it perform gc on all PHP sessions? or just the sessions for that VirtualHost? Or other sort of partioning?

I'm trying to gauge wether I need to tune the gc_probability setting for a given VirtualHost, for the whole server, or what.

1
  • Oh! Ok, will do
    – JDS
    Sep 30, 2011 at 12:55

1 Answer 1

2

If the probability is set to 1/100, does that mean that any Apache thread that runs a PHP process goes into the pool of processes that may have gc run?

If that process touches the session [session_start()], then yes, it may run garbage collection.

If you need different virtual hosts to have different garbage collection and sessions then you should use the session.save_path option to set a different path for each virtual host. You can do this in your apache virtual host config with a directive like `php_value session.save_path "/srv/www/www.example.org/sessions". If you have several different applications running with different session requirements you may need to set different paths, and GC.

Honestly though PHP session garbage collection isn't that great. You might be better off disabling it completely and using an script launched from cron to periodically clean up old sessions. Or another alternative, that requires support in the PHP application would be to store your sessions in a database.

If you are hosting stuff for external parties, then you almost certainly want to set up a separate session directory for each virtual host.

2
  • Hey, do you have any references to back up these statements? Thanks
    – JDS
    Sep 30, 2011 at 13:01
  • Also, we are putting sessions in Memcache. Does the PHP gc session cleanup operate the same way against memcache sessions? (i.e. the probability of cleanup running on any given thread is calculated the same way). Or is all the documentation for files-based sessions?
    – JDS
    Sep 30, 2011 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .