Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does the php garbage collection (gc) throw an error if SESSION and COOKIE data is used
    text
    copied!<p>I sometimes need to use both $_SESSION and $_COOKIE as well as <strong><a href="http://de3.php.net/manual/en/function.setcookie.php" rel="nofollow noreferrer">setcookie()</a></strong> inside some php script. They both work fine. <strong>But ...</strong></p> <h1>The problem:</h1> <p>Every now and then the <strong><a href="http://de3.php.net/manual/en/features.gc.php" rel="nofollow noreferrer">php garbage collector</a></strong> fires and throws an error on pages that run scripts with both $_SESSION and $_COOKIE usage. The error being:</p> <blockquote> <p>session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)</p> </blockquote> <p><strong>By the way</strong><br> I use these php.ini settings:</p> <pre><code>session.gc_probability = 1 session.gc_divisor = 100 session.gc_maxlifetime = 1800 </code></pre> <p><strong>Considerations</strong><br> There is much discussion on the net about this phenomena, but the only relevant idea comes from the <strong><a href="https://bugs.php.net/bug.php?id=19029" rel="nofollow noreferrer">php bug report forum</a></strong>. Scroll to the very end of the page and find:</p> <blockquote> <p>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!</p> </blockquote> <p><strong>The hack</strong><br> 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 @<strong><a href="http://de3.php.net/manual/en/function.gc-disable.php" rel="nofollow noreferrer">gc_disable()</a></strong>. But a hack, is a hack, is a hack, <a href="http://en.wikipedia.org/wiki/Rose_is_a_rose_is_a_rose_is_a_rose" rel="nofollow noreferrer">is a hack</a> ;)</p> <p><strong>Suggestions?</strong><br> Use the php.ini setting <code>session.gc_probability=0</code> to kill off the garbage collection altogether as discussed in <strong><a href="https://stackoverflow.com/questions/2904862/issues-with-php-5-3-and-sessions-folder">this answer</a></strong> or <a href="http://vvv.tobiassjosten.net/php/php-session-garbage-collection" rel="nofollow noreferrer">here</a> and <a href="http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage" rel="nofollow noreferrer">here</a><br> <em>Result:</em> Does not prevent the gc from running on my site, oddly enough. Why? I don't know.</p> <h1>Solution:</h1> <p>After setting a <a href="http://de3.php.net/manual/en/session.configuration.php#ini.session.save-path" rel="nofollow noreferrer">session.save_path</a> the garbage collection stopped throwing errors. I'm also using the default "session.gc_" directives now. PHP-version 5.4.9</p> <pre><code>session.save_path = /website/sessions </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload