note 112640 deleted from function.session-set-save-handler by googleguy

From: Date: Mon, 08 Jul 2013 08:58:56 +0000
Subject: note 112640 deleted from function.session-set-save-handler by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195497@lists.php.net to get a copy of this message
Note Submitter: Simone China ---- For those who use tons of Ajax requests in newest coding, with heavy access and session stored in database, might find that the database is constantly loaded heavily when a single-table session approach is used. In my case, even crashing once a month or so under the most extreme conditions... If anyone run into this issue, this is what worked for me. I have used a different approach to spread the load across multiple tables. Basically the table name contains a prefix like "__session_" followed by the session ID. In this case, each session has its own table and when select/insert/update, it will greatly reduce the number of locks required to make it run. The result is that the entire system is a lot smoother with lot less load on the database, because activity is not concentrated on one single table. The gc in this case is a bit more complex, because you have to scan active sessions and check the expiration, but with this simple query you can gather all of them rapidly: SHOW TABLES FROM [mydb] WHERE Tables_in_[mydb] LIKE '__session_%'" If you replace [mydb] with your actual DB name, this query will return the name of each table that start with "__session_" or whatever prefix you want to use, then you can read the update date into each of the table. Slightly more complex but in Ajax environment seems to be the best approach. Hope it helps other who run in the same issue ! Cheers, Simone

« previous php.notes (#195497) next »