I am coding a website in PHP and Javascript which implements private messaging functionality, and i wanted to have it so when a user recieved a new message it notifies them (by a flashing ‘mail’ icon at the top of the screen).
The question is how to implement this functionality without having to check the messages database for unread messages to the specified user every time they load a page, it seems like too much server load for every user to perform on every pageload.
Can anybody suggest a more efficient method? It doesn’t matter if the user isn’t notified instantly upon recieving a new message.
Thanks!
To avoid doing it every page load you could have some javascript within a timer function that calls to the database and checks to see if the user received messages. As Am said if you just have a flag set on the user table you can just do a
Now that said a select statement like that by itself being ran every time a page loads really won’t increase the load on your server that much, unless you are running a site with significant amounts of users.