note 112640 added to function.session-set-save-handler

From: Date: Mon, 08 Jul 2013 07:07:01 +0000
Subject: note 112640 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-195496@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.199 Probable Submitter: 183.27.162.94 ---- Manual Page -- http://php.net/manual/en/function.session-set-save-handler.php Edit -- https://master.php.net/note/edit/112640 Del: integrated -- https://master.php.net/note/delete/112640/integrated Del: useless -- https://master.php.net/note/delete/112640/useless Del: bad code -- https://master.php.net/note/delete/112640/bad+code Del: spam -- https://master.php.net/note/delete/112640/spam Del: non-english -- https://master.php.net/note/delete/112640/non-english Del: in docs -- https://master.php.net/note/delete/112640/in+docs Del: other reasons-- https://master.php.net/note/delete/112640 Reject -- https://master.php.net/note/reject/112640 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195496) next »