Ajax,PHP,MySQL聊天

I am new to Ajax and was wondering if this method is good enough to create a chat application. My question is this: Would Ajax + php + mysql have performance issues if I were to have lets say a million users? Would it lag? would I be able to scale?

Here is my code:

     var inty = setInterval(function()
  {

  var qt = document.getElementById("friend_name_goes_here").innerHTML;
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("chat_div").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "getchat.php?q="+qt+"&w="+me_name, true);
  xhttp.send();
  //console.log(qt);
}, 300);

That's the ajax part and then on the "getchat.php" is where I would query the database.

I'm pretty much new to this. Any guidance would be appreciated!

The mysql row would look like this: John - Hallo, Bob!

Bob - John, you don't understand ajax!

Ajax approach is very bad for such things like live chat. Your php script will be called very frequently and it will be very heavy overload..

For the purpose you are looking for, i would recommend WebSocket.

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

Your will need use comet server for delivered message from server to other clients.

In your rialization will be too many queries to server per second. And user will receive messages with interval of 300 ms, but if you will use comet server users will be received message immediately.

Your will get problem with performance on 10 or 20 users online in php shared hosting or small vps.

For example you can use this tutorial about using CppComet with php.

CppComet will install persistent connections via websockets with javascript. And you can send requests to CppComet using api from the php code when you need to send any message to other users.