I am making a live chat, which involves long-polling to receive messages asap. However, since afaik web sockets are not supported cross-platform, and i couldnt find a true long polling chat example, i made a similar thing, which i am actually not sure in.
What i do is i call the script in background, which executes query each 200ms until new message appears. And this is the thing im curious about - do i execute it too often? Lets say i have around 100 ppl using this chat so it will be like 500 queries per second. How will this affect the server perfomance? Posting code im using below:
while (($x < 99) && ($allowloop))
{
$query = mysqli_query($con, 'SELECT * FROM messages');
if (mysqli_num_rows($query) == 0)
{
usleep(200000);
$x = $x + 1;
} else {
$allowloop = false;
}
}
#processing results
Any tips and suggestions appreciated