I'm trying to do some long polling on my site for notifying users of incoming mail. I would be using mysql for database purposes. Would it be safe to check mysql if there's an update to the table? Would this cause the site to slow down as it will constantly look for an update? How would you even check if mysql is updated?
a code would look something like this
while($currentTime <= $lastTime){
usleep(10000)
clearstatcache();
$sql = mysql_query("SELECT time FROM timestamp WHERE $currentTime = timestamp");
$row = mysql_fetch_array($sql);
$currentTime = $row['time'];
}
So basically, it will keep running until theres a new timestamp in the database, but is this efficient where its making the server look into my database every 10seconds?
Thanks
解决方案
You could use AJAX and let the client side poll your server every X second. But you might describe your problem at a more detailed level...
Other thing possible is cron, but you'll have to provide more infos.