Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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)

share|improve this question
2  
a web based multiplayer game for android? o.o –  Gustavo Maciel Feb 9 '12 at 9:46
4  
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. –  Tetrad Feb 9 '12 at 17:09
    
Will you be accepting an answer? –  lochok Feb 22 '12 at 3:41
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
WHAT? PHP isn't stateless if you run it as a daemon! Of course, you wouldn't want to do it anyway, but still... –  Lohoris Feb 10 '12 at 17:05
    
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. –  Lohoris Feb 11 '12 at 14:06
    
@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. –  eBusiness Feb 11 '12 at 18:49
1  
Oh, you want constructive, sorry, your request is accepted: echo '<?php while(1);' >daemon.php php daemon.php & –  Lohoris Feb 13 '12 at 8:22
add comment

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.

share|improve this answer
6  
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... –  kaoD Feb 10 '12 at 14:08
3  
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. –  Nate Feb 10 '12 at 16:28
    
+1 for java.... –  stephelton Feb 10 '12 at 16:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.