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
0

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.

 

This article was written quite a while ago (9 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • PHPStorm: 42 Tips and Tricks (47min video talk by Mikhail Vink at Dutch PHP Conference 2015)PHPStorm: 42 Tips and Tricks (47min video talk by Mikhail Vink at Dutch PHP Conference 2015)
  • What’s new in PHPStorm 9What’s new in PHPStorm 9
  • Experimenting with HHVM at Etsy (Link)Experimenting with HHVM at Etsy (Link)
  • Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)
  • Install MINI in 30 seconds inside Ubuntu 14.04 LTSInstall MINI in 30 seconds inside Ubuntu 14.04 LTS
  • MINI2, an extremely simple barebone PHP application on top of SlimMINI2, an extremely simple barebone PHP application on top of Slim
  • MINI, an extremely simple barebone PHP applicationMINI, an extremely simple barebone PHP application
  • How to setup / install PHP 5.6 on Ubuntu 14.04 LTSHow to setup / install PHP 5.6 on Ubuntu 14.04 LTS
  • Support FLARUM, the future of PHP forum scripts (with some dollars on Kickstarter)Support FLARUM, the future of PHP forum scripts (with some dollars on Kickstarter)
garbage collectorgcPHPsessionsessionstimeout
Share this

Leave A Comment Cancel reply

css3-chrome-font

[Link] Retinafy your Site / Device by Nijiko Yonskai

A simple one-page Gist with all the information you need to make your sites retina-ready: Nijiko Yonskai – Retinafy your

css

How to center a div vertically and horizontally (modern methods, without fixed size!)

“How to center a div” (inside another div or inside the body itself) is one of the most discussed questions

php uk conference

PHP Opcache Explained by Julien Pauli (video from PHP UK Conference 2014)

The title says it all. A VERY deep explanation on how OpCache works. If you never heard of this excellent

hiphop php

PHP’s HipHop outperforms PHP 5.5 with Zend OPCache and Nginx by 15-20 times

A very interesting benchmark on www.alexfu.it shows excellent comparisons of plain PHP on Nginx (PHP 5.3 I think) PHP on

Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)

A very interesting talk from Latvia’s (not 100% sure) PHP usergroup meeting: Thomas Lohner (of SysEleven) explains why some of

hiphop php

HipHop VM reaches 100% green Unit Tests in Laravel, Drupal, Slim, CodeIgniter etc.

In September 2013 the PHP HipHop VM dev team wrote a very interesting article [1] about failing Unit Tests of

php

How to install/setup latest version of PHP 5.5 on Debian Wheezy 7.0/7.1/7.2 (and how to fix the GPG key error)

Please note: This works fine. But this package will also upgrade your apache to version 2.4 which has different config

How Snapchat wants to earn money (by establishing vertical videos)

Snapchat is worth 15-19 billion dollars. An insane number, making everybody ask: How the hell is this possible, why has

java vs php

Switching from Java to PHP. Seriously. A very interesting and pre-judice-free talk with Ph.D. Aris Zakinthinos

Ph.D. Aris Zakinthinos, CTO of achievers.com, a well-scalability-experienced guy and former IT employee of the military, has just delivered one

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

1/4

Categories

Search

The New Era of JavaScript (28min conference talk, Jack Franklin, 2013)
php uk conference
PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)
vagrant
How to setup a local server (in a virtual machine) with Vagrant in PHPStorm
offf-2014
Europeans: Get ready for OFFF conference / festival in Barcelona, May 2014
O’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for free
sass
[german video] Modernizing and minimalizing frontend markup code at AutoScout24
How to hack time (KUNG FURY promo campaign)
ubuntu-14.04-lts
First view: Ubuntu 14.04 LTS brings PHP 5.5 and Apache 2.4
First look on Gitter, the chat for GitHub
Adobe releases Firebug-like developer tools to edit and extract PSDs
digitalocean coupon
DigitalOcean VPS coupon codes for december 2013 and early 2014
anti block adblock
Show ads to ad-blockering visitors – with PageFair.com
october cms
October CMS, built on top of Laravel, is beautiful, clever and on the way to be the new #1 CMS
vagrant
A preinstalled Vagrant box with PHP HipHop / HHVM and Ubuntu 12.04 (Precise Pangolin)
Bézier Curves – Under the Hood (4min video)

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
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT