Skip to content

Instantly share code, notes, and snippets.

@falexandrou
Last active April 5, 2018 14:19
Show Gist options
  • Save falexandrou/032d4072bf06fba8bc8eaa29b4334a2f to your computer and use it in GitHub Desktop.
Save falexandrou/032d4072bf06fba8bc8eaa29b4334a2f to your computer and use it in GitHub Desktop.
PHP Force Garbage Collection
<?php
# If you've exceeded the number of inodes on your server,
# you could as well run `php -a` so you get the interactive shell running
# and then copy & paste the following lines into
# Make sure we're using files as a session save handler
ini_set('session.save_handler', 'files');
ini_set("session.save_path", "/var/lib/php/session");
# The probability of performing garbage cleanup is the ratio:
# session.gc_probability / session.gc_divisor
# so in order for it to be "1" (100% probability)
# we need both settings to be equal:
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);
# triggering a session start will have the garbage collection process running before the actual session starts
session_start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment