Page 2 of 2

Posted: Sun Apr 30, 2006 10:19 pm
by santosj
scottayy wrote:SantosJ, your code sample does indeed hit the server with a query on every page load; which would be what I'm to avoid. :)
That is because on most users, they stay more than a minute on the same page, depending on the information of the site. From my experience with using cron jobs has always been with online browser games. The host that I have gives enough Mysql resources to be able to not worry about stuff like this.

What I'm trying to say is that the time it takes to fetch the information from the database won't matter compared to the other stuff you'll probably have going on. Now, all of the mysql queries do add up, which then you would do good to have some caching. In my experience, you would only need to cache mysql queries that you loop over.

Using the Mysql Database is the easiest method, but I have another solution. Using all files, but it would be hella difficult, at least for me anyway.

Not using the Mysql Database at all

If you store your session files in a folder where you can get to them (should be doing this anyway), then you can iterate through them checking the modify time. If it is under a minute, then you enter into the file and check the data. Have to unserialize the data.

If you don't see any user authentication information, then the user is a guest. If there is then you'll have to decide depending on if you put in the session that the user is a regular member or admin (if you do for purposes of this cron job, then please don't use the info for the sakes of the web site).

You then serialize the online users array into a file and use that file, unserializing the data for the site.

In this way, you never hit the database, unless you don't store the rank or user in the session.

Um, in which case it would be a really good idea to put this in a cron job, just so you can clear out any sessions that are dead for security (not after a minute but after the time is greater than 45 minutes or however long you set the session to be).

Posted: Sun Apr 30, 2006 11:35 pm
by shoebappa
ADODB has query caching built in... Not sure if you're using ADODB or not but I have only good things to say about it.

http://phplens.com/lens/adodb/docs-adodb.htm#caching