While my CakePHP application was running, sometimes I got the following error:
Notice (8): session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) [CORE/Cake/Model/Datasource/CakeSession.php, line 629]
at first, I tought there was a mistake in my code, then, after studying php session, I noticed that this error was linked to the garbage collector.
The garbage collector cleans up expired sessions.
It is called randomly by PHP internally when a session starts or when session_start() is invoked.
The frequency this is called is based on the session.gc_divisor and session.gc_probability configuration directives.
session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. session.gc_divisor defaults to 100.
So, to avoid this error there are two ways to follow:
- Extend permissions to /var/lib/php, but this makes your system more insecure
- Set different value for session.gc_divisor and session.gc_probability
Someone says to set session.gc_probability to zero. I prefer to set session.gc_divisor to 1000.
Using the first solution, you will be sure the GC won't ever be called.
With the second option, the GC will be called after a session_start() 1/1000 times….