I have set the gc_maxlifetime in my config.yml file to 300. But its not working. Symfony2 still takes the value set in php.ini
Symfony version is 2.4.4
Try setting the cookie_lifetime parameters of the session config key.
session:
cookie_lifetime: 300 # override php.ini config
as described here
hope this help
Here is my approach (gotten from Drupal configuration):
set handler to native_file (i'd use PDOSessionHanlder, but seems it's not very stable);
create a seesions directory under app folder;
config.yml file:
session:
handler_id: session.handler.native_file
cookie_domain: %cookie_domain%
name: SFSESSID
cookie_lifetime: 2000000 # change this if you want
save_path: "%kernel.root_dir%/sessions"
gc_divisor: 100
gc_maxlifetime: 200000 # change this if you want
gc_probability: 1
Related
I have this code in framework.yaml :
session:
handler_id: ~
cookie_lifetime: 43200
gc_maxlifetime: 43200
I want the session to be alive about 12 hours, but after some minutes the session expire. What else modification should I do ? Thx in advance.
If I remember right, your current configuration make PHP save session files inside /var/lib/php/sessions and this directory always checked and PID inside it removed by a cron job configured in php.ini via gc_maxlifetime.
To fixed this issue you have to override the session handler and make Symfony handle the session using handler_id and save_path option as the following:
framework:
session:
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
cookie_lifetime: 43200
gc_maxlifetime: 43200
I am new to PHP, Symfony and Redis and have a query around integration of Redis with a symfony project deployed on Apache httpd as the server for session management.
The below is the software's and their versions that I am using
OS - CentOS 7
Redis - 3.2.4 - Built Redis from the source code
Symfony - 2.8
PHP 7 - Installed the below packages
php70w
php70w-cli
php70w-common
php70w-fpm
php70w-opcache
php70w-pdo
php70w-pear
php70w-process
php70w-xml
php70w-pecl-redis
I have made the below entries in php.ini file
session.save_handler = redis
session.save_path = "tcp://<<ip address of redis server>>:6379"
session.auto_start = 1
What is confusing me is do I have to write session management through my symfony code using phpredis client or should it happen automatically.
Please let me know which method I should use to go further as the redis server does not seem to be populated with the session.
All the above configurations have been done by referring the below link and has been made centos specific
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04
Thanks.
You have to change default session handler. To omit Symfony session handler and use PHP instead set the handler_id option to null in settings.yml:
framework:
session:
handler_id: null
http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
The problem was with Apache server on which I had hosted my Symfony application.
Apache had mod_php enabled and in Apache's conf.d folder I had a file named php.conf. It had properties like the ones below
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
I commented the above values and added the below and it worked. It looks like the configuration values present in php.conf in Apache's conf.d folder overrides the value of the same properties present in php.ini.
php_value session.save_handler "redis"
php_value session.save_path "tcp://<ip address of redis>:6379"
After making the below changes I have been able to see my php sessions on my redis server.
Thanks.
I'm facing a really weird issue with an application i'm working on based on symfony2 (2.5).
Long story short:
in the config.yml file i have this:
framework:
...
session:
name: "a_given_name"
# THE FOLLOWING LINE CAUSES THE PROBLEM
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/sessions"
cookie_lifetime: 2629744 #1 month
gc_maxlifetime: 2629744 #1 month
...
And session does not work!
I checked everything, the system create the files but those files are always empty.
Changing the entry realated to "handler_id" in config.yml to: "~" everything works fine.
framework:
...
session:
# CHANGING TO THE FOLLOWING -> IT WORKS
handler_id: ~
...
But, as stated in the docs, the "session.handler.native_file" is the default hanlder... so it should work anyway...
Any help about it?
Thanks a lot...
I faced the same issue when running Vagrant machine.
I recommend to move sessions out of the synced folders (default /var/www/html) to new location, e.g. /home/symfony/sessions
framework:
session:
handler_id: session.handler.native_file
save_path: "/home/symfony/sessions/%kernel.environment%"
Also, helpful article:
https://coderwall.com/p/h3i5mw/symfony-session-problems-with-vagrant
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.
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
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'
I turn on caching the component by editing cache.yml file in my module
_startpage:
enabled: true
contextual: true
lifetime: 60
There was no time difference after that but I think the component is cached because there is a symfony cache box over it (With cache info). I realized that the number of queries to DB is the same as without caching - component for sure execute some queries so why the number of queries did not changed?
Solved.
factories.yml
view_cache:
class: sfFileCache
param:
automatic_cleaning_factor: 0
cache_dir: %SF_TEMPLATE_CACHE_DIR%
lifetime: 86400
prefix: %SF_APP_DIR%/template