I sometimes need to use both $_SESSION and $_COOKIE as well as setcookie() inside some php script. They both work fine. But ...
The problem:
Every now and then the php garbage collector fires and throws an error on pages that run scripts with both $_SESSION and $_COOKIE usage. The error being:
session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)
By the way
I use these php.ini settings:
session.gc_probability = 1
session.gc_divisor = 100
session.gc_maxlifetime = 1800
Considerations
There is much discussion on the net about this phenomena, but the only relevant idea comes from the php bug report forum. Scroll to the very end of the page and find:
The cause of it was that I used sessions AND cookies in one script. I commented all the 'setcookie' lines and all other cookie functions in my script and ... the problem vanished!
The hack
Well, splitting $_SESSION and $_COOKIE use to two scripts was not an option as of now, but I manualy disable the garbage collector for each script concerned via @gc_disable(). But a hack, is a hack, is a hack, is a hack ;)
Suggestions?
Use the php.ini setting session.gc_probability=0
to kill off the garbage collection altogether as discussed in this answer or here and here
Result: Does not prevent the gc from running on my site, oddly enough. Why? I don't know.
Solution:
After setting a session.save_path the garbage collection stopped throwing errors. I'm also using the default "session.gc_" directives now. PHP-version 5.4.9
session.save_path = /website/sessions