On Tue Feb 24 2009 15:51:02 Matt Nelson wrote:
> I have a web page that runs under PHP. I query a mysql database every 5-10
> seconds, with each meta refresh. This was fine and worked decent, until
> other people started using it. Now the connections have grown to a number
> that they need to be handled better. I was thinking of creating a daemon
> that runs every 5 seconds and then populates a flat file that apache/php
> would read with every refresh thus limiting the load to one connection
> every 5 seconds.
>> Does anybody have any better ideas?
Just add a timestamp and a lock. If a page request finds the timestamp is too
old, attempt to grab the lock and then do the refresh queries and update the
timestamp. If it fails at the lock, another page got it and did it, so poll
until the timestamp is changed and then go. (If you really need speed you
could implement the timestamp test to block until ready.)