Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!

I am working on a turn based web game in PHP5.

This is pretty simple game, a kind of board game: two people join a "session" and they play until one of them wins.

My problem in nutshell:

* User A and User B play a game.

* User A finished his turn
* Request will be sent to the server to perform necessary operations.
* Now it is time for User B to move..

But how could I notify User B about this?

I mean, now the server has to communicate with the other user, the one that is inactive, not the one that initiated the request.

I know that this could be implemented using some kind of periodic AJAX call that checks whether or not the opponent finished his turn etc, but such a thing generates a huge number of requests.

Isn't there a better way to solve this?

I'm thinking of something like this:

* User A's turn ends
* Server saves his score
* Server contacts User B
* User B's turn gets started.

Is this possible using PHP? Should I use comet style AJAX? Or is there a better way to do this?

Any help would be appreciated!

Thanks in advance!
Posted

Yes it is possible, it is called Comet. But I'd look for kind of Java solution if you expect large player number. Talking about comet you can use nginx as your webserver and here is the module:
Here :)

Sorry, didn't notice comet in your post. PHP can create also sockets that can be used in connection with flash/flex. May be this is what you need?
 
Share this answer
 
v2
no noob u can write this in PHP also what you do is have a feild on a database table which will be used by a condtional statment and u can check to see whos turn it is.
 
Share this answer
 
Comments
Peter_in_2780 16-Aug-10 20:59pm    
Reason for my vote of 1
"Whose turn?" is not the problem. How to notify the other player is the problem he's trying to solve.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900