Multiplayer PHP AJAX Game

I am planning a relatively simple online multiplayer game, and I'm at a standstill about what to use for communication between player and player.

More about the game:

  • 6 players
  • Chat
  • 30 second rounds (breaks)
  • Time synchronization is important.

The players choose and act, and at the end of the round an action is performed, there is a short break in the details of the action and a new round begins.

I decided to completely create this game in JS and PHP (of course AJAX). I just don’t know what I should use for client-client interaction. At first I planned to use constant AJAX calls with 1/2 second support in a PHP script using mySQL to store game / user data, but I'm afraid it will be too slow and unpredictable.

I was considering using something like XML instead of mySQL and using something like the php fopen () function - what do you guys think about this?

I read in this question here , where the poster is considering using XMPP, could this be a good solution?

Should I go for the socket? Is it necessary for a game that does not require much data exchange? What will be required for this?

Any suggestions for round time synchronization? Or is that what I really need to worry about?

I am open to all suggestions and really appreciate any help I can get.

+1
source share
3 answers

, . - AJAX. p2p, , , . JS/PHP, Google, . , , MySQL XML ( MySQL , XML - , , , , ).

+2

PHP/JS/Ajax, usleep() , ajax, - . .

, , , 5 10 ajax, , .

, javascript (jQuery), ajax- .

+2

JS/PHP, : . , , , XMLHttpRequest php script, (, , " ". , - , XMLHttpRequest PHP , PHP - , , , . PHP . PHP, :

<?php
#First, set infinite time limit
set_time_limit(0);
#record last modification time
$f1=filemtime('./nameoffile.txt');
#wait until the file changes
while($f1===filemtime('./nameoffile.txt'){
    #have a 10,000 microsecond break between each check so you do not use too much resources
    usleep(10000);
readfile('./nameoffile.txt');
?>

WebSockets HTML5. , PHP, .

+1
source

Source: https://habr.com/ru/post/1692828/


All Articles