Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The answer to 2) is - id depends. Let me explain: in order for the session handler to function properly you really should implement some type of lock and unlock mechanism. MySQL conveniently have the functions to lock table and unclock table. If you don't implement table locking in session handler then you risk having race conditions in ajax-based requests. Believe me, you don't want those.</p> <p>Read this detailed article that explains <a href="http://thwartedefforts.org/2006/11/11/race-conditions-with-ajax-and-php-sessions/">race condition in custom session handler</a> : </p> <p>Ok then, if you add LOCK TABLE and UNLOCK TABLE to every session call like you should, then the your custom session handler will become a bit slower.</p> <p>One thing you can do to make it much faster is to use HEAP table to store session. That means data will be stored in RAM only and never written to disk. This will work blindingly fast but if server goes down, all session data is lost.</p> <p>If you OK with that possibility of session being lost when server goes down, then you should instead use memcache as session handler. Memcache already has all necessary functions to be used a php session handler, all you need to do it install memcache server, install php's memcache extension and then add something like this to you php.ini</p> <pre><code>[Session] ; Handler used to store/retrieve data. ; http://php.net/session.save-handler ;session.save_handler = files session.save_handler = memcache session.save_path="tcp://127.0.0.1:11215?persistent=1" </code></pre> <p>This will definetely be much faster than default file based session handler</p> <p>The advantages of using MySQL as session handler is that you can write custom class that does other things, extra things when data is saved to session. For example, let's say you save an object the represents the USER into session. You can have a custom session handler to extract username, userid, avatar from that OBJECT and write them to MySQL SESSION table into their own dedicated columns, making it possible to easily show <strong>Who's online</strong></p> <p>If you don't need extra methods in your session handler then there is no reason to use MySQL to store session data</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload