So I am starting a game with a friend as a small project, and we are considering what game servers would we need.

Firstly, the game is a multiplayer(player vs player) game, for example, like an online chess game. However it is real time, so the latency cannot be too high. The players basically take turns, but in a real time fashion. The platform is going to be Android (and perhaps extend to iOS in the future)

The server would need to synchronize the players' moves to each other devices.

I don't really need anything large scale and I am thinking of using PHP since the volume of data isn't really that big, this is like a web-based game with a requirement of a slightly lower latency.

What would be the advantages and disadvantage of using Apache + PHP for a game like this?

If that seems to be a bad choice, I would be grateful if you can share your experience with me. Thank you.

(We are both programmers and we are familiar with Java C++ Obj-C Apache PHP Tomcat JSP Javascript)

  • 2
    \$\begingroup\$ a web based multiplayer game for android? o.o \$\endgroup\$ Commented Feb 9, 2012 at 9:46
  • 4
    \$\begingroup\$ the latency you get from the network is probably going to overpower whatever difference in technology stack you choose, assuming your hardware isn't overloaded. \$\endgroup\$
    – Tetrad
    Commented Feb 9, 2012 at 17:09

2 Answers 2


A normal PHP/Apache setup is stateless, and that sucks for a game server since it forces you to use the database for basically everything. If you can handle the extra centiseconds it may be a working solution, but server performance is going to be pretty bad.

You could take a conventional language like C++ or Java and write the gameserver in that, that is potentially the fastest option.

Alternately, especially if you intent to use HTTP anyway, you could use Node.js. Almost as easy as PHP, faster, and most important to keep you sane, allows you to share data between requests without going through the database.

  • \$\begingroup\$ WHAT? PHP isn't stateless if you run it as a daemon! Of course, you wouldn't want to do it anyway, but still... \$\endgroup\$
    – o0'.
    Commented Feb 10, 2012 at 17:05
  • \$\begingroup\$ Confirm my statement? I don't understand. If you just run a php script with a classic "main loop", it does exactly that, just like using any other language. \$\endgroup\$
    – o0'.
    Commented Feb 11, 2012 at 14:06
  • \$\begingroup\$ @Lohoris I really don't want to argue with you, I'll just say that your criticism ain't constructive. You point out an error, but you don't provide the necessary explanation. I have been through a hell of a lot of googling, and the most straightforward option for a stateful PHP server seems to be writing a server in PHP using the stream_socket_server and running this script on it's own. \$\endgroup\$ Commented Feb 11, 2012 at 18:49
  • 1
    \$\begingroup\$ Oh, you want constructive, sorry, your request is accepted: echo '<?php while(1);' >daemon.php php daemon.php & \$\endgroup\$
    – o0'.
    Commented Feb 13, 2012 at 8:22

PHP/Apache theoretically could do it. BUT - they are designed for making active webpages and will most probably not be the best tool for the job.

You would be probably better off writing a server in the language of your choice - out of your familiarities, I would suggest Java or C++. Use the relevant sockets library, and code it directly.

If it is a real time, though turn based game, I would use MySQL as a datastore, as it can interact with Java or C++ (or PHP if that is what you eventually decided to use). Make your server application Fork for each connection, read the current state of the game off MySQL and apply the rules (storing changes to the MySQL datastore, so any other players who connect will see the relevant data), provide accept the players input and output etc. This would also minimize the problems related to multithreading. However, using Forks as well as C++ (or, to a lesser extent, Java) will ensure scalability.

I will warn you - I have limited experience in the area, so you can take my answer for what it is worth.

  • 6
    \$\begingroup\$ A relational database is a bad choice for real-time games. It's a great choice as a data store, but not for gamestate. DB are good for structured data that has to be stored. Good: character level, stats... Bad: health, position... \$\endgroup\$
    – kaoD
    Commented Feb 10, 2012 at 14:08
  • 3
    \$\begingroup\$ I would use the relational database to store gamestate in the event of a server crash/reboot. The server should always operate from memory, and periodically send that memory store to the database. \$\endgroup\$
    – Nate
    Commented Feb 10, 2012 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .