We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to get/set session life cycle?



642

Hello.

It depends on the session adapter you use (see: https://phalcon-php-framework-documentation.readthedocs.org/en/latest/api/Phalcon_Session_Adapter.html) You can implement your own session adapter and control the life cycle inside it.

Note, session.gc-maxlifetime won't work! (see: https://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime) There is a good explanation here https://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes

Please, describe here which session lifecycle you need and I will try to help



6.9k
edited May '15

The configuration of session in my project: public/index.php

...
$di->setShared('session', function() {
    $session = new Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
});
...

Could you please tell me what is the default life cycle of session when using the above configuration?

Do I have to implement a new session adapter? If it is necessary, could you please give me an example including the life cycle configuration?

Thanks!

Hello.

It depends on the session adapter you use (see: https://phalcon-php-framework-documentation.readthedocs.org/en/latest/api/Phalcon_Session_Adapter.html) You can implement your own session adapter and control the life cycle inside it.

Note, session.gc-maxlifetime won't work! (see: https://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime) There is a good explanation here https://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes

Please, describe here which session lifecycle you need and I will try to help

By default a session lasts 1440 seconds (24 minutes). You can modify that setting by either changing your php.ini file, or calling ini_set() with the appropriate parameters.



6.9k

As Denis said, session.gc-maxlifetime won't work.

By default a session lasts 1440 seconds (24 minutes). You can modify that setting by either changing your php.ini file, or calling ini_set() with the appropriate parameters.



6.9k

Could anyone help?

Please explain in more detail what you are referring to by "life cycle"



6.9k

I use session to store user login data. But it seems to be invalid after 3 or 4 hours. User had to re-login the system again. I want to set this time to be 12 hours.

Please explain in more detail what you are referring to by "life cycle"

+1 to this. Same problem here.