Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
December 7, 2013
Chris
Login, PHP, Security
Comments Off on How the PHP session garbage collector really works

How the PHP session garbage collector really works

PreviousNext
php

Sessions in PHP are easy to handle, but have a tricky configuration underneath. The common opinion is, that when you close your browser, the session is gone. Actually, it’s a little bit more complicated: Have a look on these 3 lines in your php.ini:

session.gc_maxlifetime = 3600
session.gc_probability = 1
session.gc_divisor = 1000

session.gc_maxlifetime says: 3600 seconds (1 hour) after session initialization, PHP will mark this session as “outdated” and flag it as “ready to delete”. The session still exists after 1 hour! But it’s not deleted. The deletion process of all outdated and ready-to-delete file is called “garbage collection” (process), and it’s triggered – with a specific probability – when another user comes to your page and PHP has to compile something. This probability is calculated by session.gc_probability divided by session.gc_divisor. Yeah, a little bit weird, but the people behind PHP have thought about this, and there are reasons for this behaviour.

Have a look on this excellent answer on StackOverflow to read more about this topic: How do I expire a PHP session after 30 minutes?. So in general it means, that when you close your browser and open it again, and are still logged in, it has to do with PHP’s session gargabe collector process. This might happen quite often on low-traffic sites or while you are developing locally.

 

garbage collectorgcPHPsessionsessionstimeout
Share this

Install MINI in 30 seconds inside Ubuntu 14.04 LTS

This is a guideline on how to install MINI – an extremely simple naked PHP application – more or less

phpstorm 7.0 php

PHPStorm 7 has been released!

DEV METAL does not get any money for saying this and there is no affiliate link or similar. This post

Awesome next-gen PS4 graphics in “The Order: 1886”

We are entering a very interesting time: The differences between cinematic movies and video games are getting lesser and lesser.

php

How to install PHP curl extension (in 5 seconds)

It’s a common wordpress problem: PHP’s curl extension is not installed! No need to mess around in config files etc,

sass laravel

SASSmeister is a real-time JSfiddle for SASS / CSS. Awesome!

Excellent tool for testing out SASS in real-time! SASSmeister.com offers a responsive (!) interface for quick SASS-to-CSS development with some

GitHub introduces revert button / rollback for merged pull requests

Once again GitHub delivers an excellent feature: Clean one-click rollbacks / reverts / undos of pull requests, very very useful,

Increase your HTML / CSS coding speed with EMMET

Codeninja.com just published a very interesting article about the excellent free code-completion/code-generation tool EMMET, which allows you to create huge

Google I/O 2014 – HTTPS Everywhere (video)

Excellent, essential and game-changing talk by Ilya Grigorik and Pierre Far (both of Google), explaining why you should always use

What’s new in PHPStorm 9

PHPStorm 9 has just been released a few days ago, and as a PHP developer you should definitly give it

mod-rewrite-ubuntu-14-04-lts

EOL lists of Ubuntu, Debian and CentOS for your server plannings

Chosing the right server operating system will probably save your life and avoid a lot of stress with your clients.

1/4

Categories

Search

php
PHP 5.6 announced, statically typed (!) “new” PHP announced by Facebook devs
GitHub finally introduces repo traffic stats
php uk conference
Profiling PHP Applications by Bastian Hofmann (video from PHP UK Conference 2014)
phpstorm-8
A PHPStorm shortcuts cheat sheet (for Windows, Mac OS and Linux)
php
How the PHP session garbage collector really works
phpstorm-github-code-color-syntax-theme
Get Github’s syntax highlighting colors in PHPStorm
8 awesome pure CSS spinner / loader
Compare 250+ cloud server plans with Cloud Cost Calculator
ubuntu-14.04-lts
First view: Ubuntu 14.04 LTS brings PHP 5.5 and Apache 2.4
october cms
[Link] How To Install October CMS on a VPS running Ubuntu 14.04
hack-php
Facebook releases HipHop (HHVM) 3.0, adds mysqli and support for Hack language
php
appserver.io – A New Way of Magento Enterprise Infrastructure (26min video talk)
Bézier Curves – Under the Hood (4min video)
php mvc
Preview-release of (my) “php-mvc” project (a simple php mvc barebone)
shadow dom
A quick video introduction into Shadow-DOM, the game-changing DOM-subtree-technology

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy