45

As the title state for some reason my Symfony 2.5 Application is calling the php garbage collector even when all of my php.ini files have:

session.gc_probability = 0

Does anyone know how to prevent this from happening?

Error message im getting:

Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php5)
failed: Permission denied (13) in /<path-to-my-site>/var/cache/dev/classes.php line 432 

FROM PHPINFO():

Directive               Local Value   Master Value
session.gc_divisor      1000          1000
session.gc_maxlifetime  86400         86400
session.gc_probability  0             0

I know that i can just give the www-data user permission to the /var/lib/php5 folder or change the session.save_path to somewhere that the www-data user has access to already but i want to know why this process is even getting called when it should be disabled.

Chase
  • 9,289
  • 5
  • 51
  • 77
  • did you run php_ini() to see if that setting actually took hold, or was overridden later with a `ini_set()` or a `.htaccess` php_value? – Marc B Aug 22 '14 at 19:55
  • According to phpinfo() it is 0, i cant find any ini_set() with it or any htaccess files that are overwriting it. – Chase Aug 22 '14 at 20:00
  • @MarcB Thanks for your suggestion it led me in the right direction. – Chase Aug 22 '14 at 20:14

2 Answers2

72

I found it, I guess the latest version of symfony is overwriting this by default when using the app_dev.php. The Symfony FrameworkBundle is setting the session.gc_probability = 1.

As of Symfony 3

However, some operating systems do their own session handling and set the session.gc_probability variable to 0 to stop PHP doing garbage collection. That's why Symfony now overwrites this value to 1.

If you wish to use the original value set in your php.ini, add the following configuration:

# config.yml
framework:
    session:
        gc_probability: null

https://symfony.com/doc/current/components/http_foundation/session_configuration.html#configuring-garbage-collection

Previous 2.x versions

To change this add the following to your config.yml

framework:
    session:
        gc_probability: 0

Then clear the dev cache

php app/console cache:clear

This is where it shows the gc_probability defaulted to 1. Why they dont just read from the php.ini settings im not sure.

http://symfony.com/doc/2.5/reference/configuration/framework.html#gc-probability

Chase
  • 9,289
  • 5
  • 51
  • 77
  • 1
    Thankyou! I was tryhing to determine why my garbage collection was throwing this notice: `Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php5/sessions) failed: Permission denied (13)` Your solution fixed it up great. – ChristoKiwi Nov 15 '15 at 05:23
  • 1
    Thank you! I put it in my `config_dev.yml` to keep it permanently there for my dev server. On live it doesn't seem to do that. – George Mylonas Feb 02 '16 at 11:33
6

You can set path for sessions manually. See Symfony doc on sessions directory.

# app/config/config.yml
framework:
    session:
        handler_id: session.handler.native_file
        save_path: '%kernel.root_dir%/sessions'
soundlake
  • 321
  • 4
  • 10