Question

I want to create multiplayer game with PHP. I created full OOP system for that - classes that management the whole game. I also stated to write the HTML+Canvas code for the game - and now i have a problem. For real HTML5 multiplayer game i need to use Node.js + Socket.io technology. But i don't want to leave all my PHP code and start implement all again with Node.

So i tried to use AJAX Polling so players can update the server every time they do something in the game - but the problem is - if any player close the browser or hack the javascript game timer - the server can't know about because PHP code is execute one time. I thought about create a cron-job that run every second and check if player is still active, but cron-job is limited to execute every one minute (and also i don't think it's correct method).

so what can i do? i need to leave all my work in PHP and start learning and implement all again with Node.js? There is no other option to make the server run even if PHP code has already execute?

Was it helpful?

Solution

Just a personal opinion, I am a big fan of PHP, I love it, however I do recognize when PHP is not the answer for a particular problem. PHP was not designed for real time applications, sure there are a lot of solutions for that: Ape or Ratchet but at the end I feel like I am consuming more CPU cycles than I really need. I would stick to Nodejs and socket.io since they are meant to be used by real time applications. Again, this is just a personal opinion.

OTHER TIPS

PHP it's really not what you'r looking for... you must use better technology like NodeJS & Socket IO

You can implement long polling in PHP with set_timeout(0), and then perform one AJAX with endless loop, but it's really lame

I know this question is bit old - but I just complete development a texas hold'em game with NodeJS and MongoDB and it's really incredible! PHP is out of the question when you have such those technologies!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top