I've set up a MEMORY table in my MySQL database with following columns: user_id INT UNSIGNED, lastactivity DATETIME, position VARCHAR(255)
In AppController for every user which is logged in I do a SQL REPLACE into this table on every request. Because this is table is kept in the RAM of the database machine the overhead for accessing it (read and write) is very small. I can use this table for calculating the number of current online users or display the current locations of the users on my site. Unfortunately MySQL doesn't allow TEXT columns on MEMORY tables - in this case it would be possible to use the MEMORY storage engine as a very performant session storage (Cake serializes the session data into a string). Marcus On 14 Aug., 10:52, Pillow <[EMAIL PROTECTED]> wrote: > Hi, > > I'm going to implement some online users counter on my website. The > simplest way of doing it is counting sessions active for instance for > last 3 minutes. > > I've tried using CAKE_SESSION_SAVE set to cake, and counting files in / > app/tmp/sessions/ which last modification time was greater than > time()-3*60. But it was very slow because of that gc is running very > rarely, and there are too many files to check (my website has up to > 30000 uniq visits per day). > > So, another idea is to have database driven sessions, and counting > records modified not longer than 3 minutes ago by sql query. > > However, it also have disadvantages - each $this -> Session -> read/ > write(); equals one database query. I use sessions very often, so > number of queries to database on every request has risen rapidly. > > What do you think, is it going to slow down my website? Do you have > better ideas on how to implement online counter? > > Thx, > Pillow --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
