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
logo-internet-explorer

How to professionally test on old Internet Explorer versions

If you have (or want) to test your websites and applications on older versions of Internet Explorer, then there’s a

[Link] Interesting: Designing a Nuclear Waste Warning Symbol That Will Still Make Sense in 10,000 Years

Interesting article for everybody with a faible for UI/UX: Slate – Designing a Nuclear Waste Warning Symbol That Will Still

php

Must-read PHP blog: PHPweekly.com

Probably one of the best ressources for your weekly doze of news from the PHP scene: phpweekly.com simply publishes a

PHPStorm: 42 Tips and Tricks (47min video talk by Mikhail Vink at Dutch PHP Conference 2015)

To be honest I’ve not seen the clip yet, but it sounds so awesome and everybody is upvoting it. Have

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

windows-xp-eol

Windows XP is officially dead from today. Do you know people still using it ? Punch them.

From today, April 8th 2014, Windows XP is officially dead. Basically XP was already dead in 2009 when – after

angular js

Learn AngularJS in 20 (or 90) minutes with Dan Wahlin

Definitly two of the best and most up-to-date short-introductions into AngularJS: Dan Wahlin shows how to build a full little

Bézier Curves – Under the Hood (4min video)

Take a peek under the hood to see how computers draw cubic Bézier curves, as used in design and motion

php uk conference

Profiling PHP Applications by Bastian Hofmann (video from PHP UK Conference 2014)

The title says it all: Profiling PHP applications.  

php

How to prevent PHP sessions being shared between different apache vhosts / different applications

When you run multiple applications on one server, you might run into the session-sharing problem: All your applications share the

1/4

Categories

Search

phpstorm-8
A PHPStorm shortcuts cheat sheet (for Windows, Mac OS and Linux)
symfony-framework-logo
SensioLabs, creator of Symfony and Silex PHP frameworks, gets $7 million capital
php
How to use the PHP 5.5 password hashing functions
hack-php
The first micro framework written in Hack is there: hack-mvc !
How to show memory usage (Ubuntu)
Increase your HTML / CSS coding speed with EMMET
php
How to prevent PHP sessions being shared between different apache vhosts / different applications
Compare 250+ cloud server plans with Cloud Cost Calculator
What’s new in PHPStorm 10 (Official promo video)
O’Reilly’s Programming JavaScript Applications by Eric Elliott for free (Early Access release)
phpstorm-8
PHPStorm 8 (early access version) released – for free
js javascript
How JavaScript really works – An introduction into the JavaScript call stack by Philip Roberts (20min video)
[Link] Redesigning SoundCloud by Evan Simoni
Meet the developers behind Ableton (14min video)
php uk conference
Slides & talks from PHP UK Conference 2014

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