CodeIgniter Forums
Codeigniter session times out very often - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter session times out very often (/showthread.php?tid=75769)



Codeigniter session times out very often - october11 - 03-15-2020

Hi friends,

Since late February, my application (on Live) has ben logging out users quite often, to the point of receiving angry Emails Sad

I have tried tweaking my config, but nothing has helped. Even went as far as restarting apache after updating my config.php (I don't need to do this correct?)

This is my current sessions setup on config.php
Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 0;
$config['sess_regenerate_destroy'] = TRUE;

It's similar on local, and it never ever kicks me out.

The only time I 'destroy' the session is on /logout path

Also, on 'ci_sessions' table on DB — there are a ton of empty sessions

On php.ini I now have session.gc_probability = 1

I've read the forum here, before posting. I've searched and posted on StackOverflow. It will be a month now and I still don't have a solution.

I am on CI 3.1.11

Have a few AJAX longpolls and use AJAX for almost all user action — which lead me to this article https://degreesofzero.com/article/fixing-the-expiring-session-problem-in-codeigniter.html — though since Sessions library has been completely re-written since then, I'm not sure it applies any more (?) or does it?

Any clues? I am really at the end of my rope...


RE: Codeigniter session times out very often - InsiteFX - 03-15-2020

If your doing Ajax calls you need to do a session_write_close() when you no longer
need the session.


RE: Codeigniter session times out very often - october11 - 03-15-2020

(03-15-2020, 07:58 AM)InsiteFX Wrote: If your doing Ajax calls you need to do a session_write_close() when you no longer
need the session.

Thanks tons for the reply.

Do I do this at the end each function that is being utilized by AJAX?


RE: Codeigniter session times out very often - muyassarov - 03-15-2020

I think you need to do session_write_close in the start of your Ajax functions. So session will be closed and other Ajax requests can be processed even if first request does not finish. One other thing to mention if you do session_write_close, then you could not store information to the sessions in that request, because session file will be closed for write.


RE: Codeigniter session times out very often - includebeer - 03-16-2020

You need to do a session_write_close as soon as you no longer need to write to the session data. This will release the lock to let other concurrent ajax call to access the session data in exclusive mode. It helps for performance, because it reduce the waiting time to get a lock on the session. But I don’t think there’s any effect on the session timeout.


RE: Codeigniter session times out very often - october11 - 03-16-2020

(03-16-2020, 09:29 AM)includebeer Wrote: You need to do a session_write_close as soon as you no longer need to write to the session data. This will release the lock to let other concurrent ajax call to access the session data in exclusive mode. It helps for performance, because it reduce the waiting time to get a lock on the session. But I don’t think there’s any effect on the session timeout.

Thanks all for the replies on this.

Trying this now and lets see how it plays out. I've been basically losing it : ( 

So thanks so much for chiming in for help. Hope this fixes it.


RE: Codeigniter session times out very often - GloriousLion - 05-02-2020

(03-16-2020, 09:29 AM)includebeer Wrote: You need to do a session_write_close as soon as you no longer need to write to the session data. This will release the lock to let other concurrent ajax call to access the session data in exclusive mode. It helps for performance, because it reduce the waiting time to get a lock on the session. But I don’t think there’s any effect on the session timeout.

Many thanks for that complete information!


RE: Codeigniter session times out very often - tommyshelbyop - 04-11-2021

(05-02-2020, 12:15 AM)GloriousLion Wrote:
(03-16-2020, 09:29 AM)includebeer Wrote: You need to do a session_write_close as soon as you no longer need to write to the session data. This will release the lock to let other concurrent ajax call to access the session data in exclusive mode. It helps for performance, because it reduce the waiting time to get a lock on the session. But I don’t think there’s any effect on the session timeout.

Many thanks for that complete information!

this was helpful thanks