Checking for new message using AJAX and PHP. Server overload?
I wrote a script (it may not be perfect, I'm newbie) to check for new message (using ArrowChat and Buddypress) every X mins.
It works good, but I'm worried will it overload my server? It's shared.
Code:
PHP
    
// Prepare database
global $wpdb;
$wpdb-prepare;
// Check are there new messages
$query = $wpdb-get_results( 'SELECT `id` FROM `arrowchat` WHERE `to` = "'.$_GET["user_id"].'" AND `user_read` = "0" AND `read` = "0"');
// Count messages
$x = 0;
foreach( $query as $msg ) {
  $x = $x + 1;
}
// If there are new messages, echo their number
if(!empty($query)) {
  echo $x;
}
JS:
script
function checkMessages() {
jQuery.ajax({
    type: "GET",
    url: "https://twobytwo.com.hr/check-new-msg.php?user_id='(PHP user id var)'",
    dataType: "html",
    success: function(response) {
        jQuery(".kleo-open-chat  .count").html(response);
    }
});
}
setInterval(checkMessages(), 600000);
/script
Thanks in advance.