• 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issues on database session / session driver

#1
Hi, I have a chat application build with Codeigniter 3.1.11 and jQuery ajax. I'm using database session driver. There was no issue in localhost, but when I have moved it to live server and as per increase in the accessing number of users, I have many issues with the session. One of the issue is its creating multiple session ids for a single user (Means when I'm opening a page inside my browser, its creating around 4 to 6 ids minimum inside the ci_sessions table, sometimes its more than that). And sometimes I have losing the session values (like it's resetting in every ajax call). And I have getting the below error also inside the log file:

ERROR - 2020-02-04 13:41:30 --> Query error: Deadlock found when trying to get lock; try restarting transaction - Invalid query: UPDATE `ci_sessions` SET `timestamp` = 1580823690 WHERE `id` = 'e0b75ac252a680d3ec6ad1b8589f4836b89f8bf5'


My live sever info:

Apache Version: 2.4.41
PHP Version: 7.3.13
MySQL Version: 10.3.18-MariaDB
Operating System: linux

When I'm posting this, my ci_sessions table contains 478 unique ip addresses and 5105 entries inside the table. Please anyone help with this issue. 
Reply

#2
What are your PHP ini settings for the garbage collector?
Reply

#3
(02-10-2020, 04:30 AM)Goddard Wrote: What are your PHP ini settings for the garbage collector?

session.gc_divisor=0
session.gc_probability=0
session.gc_maxlifetime=1440
session.use_cookies=1
session.use_only_cookies=1
session.use_strict_mode=0

Garbage collector is working fine, because ci_sessions table contains sessions only from 2020-02-10 (today). And one more thing, I have checked the below file (codeigniter built-in session driver file for database sessions):

 /system/libraries/Session/drivers/Session_database_driver.php

I found there is a lock of 5 minutes! I didn't understand why they are locking a row (i doubt they are locking the entire table for 5 minutes!) for 300 seconds. I have reduced that to 150 seconds and the count of dead lock occurring has been reduced now. Also found there is another thing inside the session library file:

/system/libraries/Session/Session.php

The function "sess_regenerate" simply calling the php session_regenerate_id(). As per the php manual, session_regenerate_id() will not handle unstable networks such as Mobile and Wifi and the session value may lose. I think, this can be the reason behind creating multiple sessions for a single user. That is, somehow php or apache identified my network as unstable and session library couldn't handle this situation. I think, Codeigniter native session library is not enough for my application.
Reply

#4
(02-10-2020, 05:40 AM)UC_SUJITH Wrote: The function "sess_regenerate" simply calling the php session_regenerate_id(). As per the php manual, session_regenerate_id() will not handle unstable networks such as Mobile and Wifi and the session value may lose. I think, this can be the reason behind creating multiple sessions for a single user. That is, somehow php or apache identified my network as unstable and session library couldn't handle this situation. I think, Codeigniter native session library is not enough for my application.

You can eliminate the call to session_regenerate_id() by using the following setting in /application/config/config.php

PHP Code:
$config['sess_regenerate_destroy'] = false
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.