Welcome Guest, Not a member yet? Register   Sign In
Session expiring before expiration period.
#1

My sessions seem to be expiring before their expiration period. I've researched this quite a lot and am unable to resolve it. I thought may it was down to Asynchronous ajax calls (session race condition) so I extended the session class via MY_Sesssion.php to only regenerate the session if it's not an AJAX call. 

I've included both that function and my config below. I'm using CI version 3.1.7

PHP Code:
class MY_Session extends CI_Session {

 
   // --------------------------------------------------------------------

 
   /**
     *
     * Do not update an existing session on ajax or xajax calls
     *
     * @access    public
     * @return    void
     */
 
   public function sess_regenerate() {
 
       $CI get_instance();

 
       if ( ! $CI->input->is_ajax_request())
 
       {
 
           parent::sess_regenerate();
 
       }
 
   }


Config:
PHP Code:
$config['sess_expiration']        = 7200//= 2 hours
$config['sess_driver'                 'database';
$config['sess_save_path']        = 'ci_session';
$config['sess_table_name']        = 'ci_session';
$config['sess_match_ip']        = FALSE;
$config['sess_time_to_update'         300// 300 = 5 minutes
$config['sess_regenerate_destroy'     TRUE
Reply
#2

Does your server/PHP time have the same timezone as your MySQL Database?
Reply
#3

Hi rhodium, thanks for the response.

MySQL
global time zone is UTC, session time zone is Europe/London.

PHP
date_default_timezone_set: Europe/London
date.timezone: Europe/London

So yes, I believe so.
Reply
#4

You can follow this link https://stackoverflow.com/questions/5500...s-expiring this may help you.
Reply
#5

(08-17-2018, 07:18 AM)Susan Burling Wrote: You can follow this link https://stackoverflow.com/questions/5500...s-expiring this may help you.

Appreciate the help, but have already read that. This is essentially my last port of call as I've googled it to death.
Reply
#6

Just following on from this. I believe this is my issue: https://github.com/bcit-ci/CodeIgniter/issues/154

Originally only on AJAX calls, but I can reproduce the issue by session sess_time_to_update to a low value, and opening several tabs which causes simultaneous requests.
Reply
#7

(08-29-2018, 04:12 AM)alan1o Wrote: Just following on from this. I believe this is my issue: https://github.com/bcit-ci/CodeIgniter/issues/154

Originally only on AJAX calls, but I can reproduce the issue by session sess_time_to_update to a low value, and opening several tabs which causes simultaneous requests.

Have you tried using session_write_close() as described in the session documentation "A note about concurrency"?

It's a singularly useful call inside ajax requests.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB