So I created really simple chatbox in php. It works very good, but I had to set up script that is nonstop loading data from database to the chat window (not probably the most efficient way, that's why I am asking):
<script type='text/javascript'>
$('#chatbox').html('Loading...');
$(document).ready(function() {
setInterval(function(){loop()}, 0);
function loop(){
$('#chatbox').load('/chatbox.php');
}
});
</script>
And in chatbox.php:
include '/classes/class.chatbox.php';
$chat = new Chat();
$chatboxMsg = $chat->getNewMessages();
echo $chatboxMsg;
But this isn't the problem. My question is, how can I load the data (=refresh chat) for ALL users that have opened chat window, only when someone post new message (=insert new row to the db), without running script that is checking something every second?