I'm creating a text based rpg in php/mySQL and I've come up to a dead end in regards implementing the pvp aspect of the game. First off is this even possible in php/mysql? If so, how would I go about implementing it? I was thinking something like having an arena or room where you can go to battle. Then have a list of everyone else in the room who is looking for a fight. You can then make a request to fight someone from the list. Once the request has been accepted, then you can begin the fight. In terms of this mechanic, it seems to me something similar to what I am after is described in the following question: https://stackoverflow.com/questions/8934681/database-design-for-turn-based-game

P.S. The combat system is turn based. So first you attack, then the enemy attacks, and so on until you have a winner.


2 Answers 2


I'm not all that familiar with PHP and MySQl but this is how I would go about it.

First I would create a datatable for all players in a room and their status (just chillin or looking for a fight).

Then link the room table to another table that contains challenge requests that links the player ids for two players in the room datatable.

You could then query the challenge table every few seconds to see if anyone is trying to pick a fight with the current player and prompt the player with any spending fight requests. If a player accepts the request then you can delete all requests that are linked to the player or if they refuse the request you can just delete the request that you showed the user.

As for the actual fighting, I guess I would create a temporary table that stores player actions (a row would have something like a player id, move id, and random value for determining what the move does (status effect applied, damage done, or whatever just use the random number to figure out what happens playerside, don't store the result of a move in the table because that would just complicate things. The random value should be enough for producing the same result on both players game). As long as you keep querying the table at regular intervals and checking who made the last move it should be pretty simple.

All that being said, I'd have to agree with eBusiness in that PHP/MySQL might not be the best combo for a multiplayer game. You are more than welcome to try and use it as a learning experience if things don't work out well. Just don't beat yourself up if you can't make things work the way you want them to exactly.


It is possible. You could have a list of players in the room in the database, then JavaScript on the clients should once in a while send a request to get an updated list. Any player that hasn't sent such a request for some time should be taken off the list. I guess you'd have to keep the game state in the database as well.

All this said, a common PHP/MySQL setup is in general horrible for game programming. It is slow at runtime and it forces you to run way too many database queries.

Node.js for instance takes a bit more work in order to get a basic website running, but it is way better suited for a game server.


You must log in to answer this question.

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