Amaynut
Amaynut

Reputation: 4271

Silex session set a lifetime

How to change the default session lifetime in Silex. The default value is 30mn;

The doc http://silex.sensiolabs.org/doc/providers/session.html#usage is giving a clue but doesn't show an example how to do it.

When I set a session like this:

$app['session']->set('username', 'my username');

The session variable is set but it expires in 30mn.

Upvotes: 1

Views: 2748

Answers (2)

David
David

Reputation: 568

Don't forget that you must have some coherence between lifetime settings in Silex and lifetime settings in your php.ini.

By default, PHP lifetime sessions are set to 1440 seconds. If you don't change this default value, the session garbage mecanism (run by /etc/cron.d/php5) will remove "old" sessions (i.e. sessions with 1440 seconds of inactivity).

Here is the explaination of /etc/cron.d/php5 :

#  This purges session files in session.save_path older than X,
#  where X is defined in seconds as the largest value of
#  session.gc_maxlifetime from all your SAPI php.ini files
#  or 24 minutes if not defined.  The script triggers only
#  when session.save_handler=files.
#
#  WARNING: The scripts tries hard to honour all relevant
#  session PHP options, but if you do something unusual
#  you have to disable this script and take care of your
#  sessions yourself.

Upvotes: 1

keyboardSmasher
keyboardSmasher

Reputation: 2811

Silex uses the Symfony Components. You can set the expiration using the migrate method for a certain session.

E.g.: $app['session']->migrate(false, 3600);

Docs

To set the expiration for all sessions:

$app['session.storage.options'] = [
    'cookie_lifetime' => 3600
];

Source

Upvotes: 2

Related Questions