Search code examples
phpjavascriptajaxmultiplayer

Keep track of connected clients, using only JavaScript and PHP


I'm making a basic multiplayer game, and I can't use node.js and socket.io because it's going to be running on a remote server I don't have much control over.

Currently, client-side, I have an ajax request that pings a server-side PHP file every 3 seconds with a unique ID, and if a unique ID isn't pinged within 6 seconds, the player is considered disconnected.

Are there any other techniques that may be more efficient to keep track of connected clients using only JavaScript and PHP?


Solution

  • If the browser supports Web Sockets, that is what socket.io primarily uses. You should be able to tell when the socket gets disconnected, so you just need to find a Web Socket library for php (here's one I haven't personally tried and just pulled out of Google).