What server should I use for a PHP Online Game?

11 replies
I've created online games before using php and flash but they took too long for the server and the game to communicate. You would press 'up' and then the following would happen:

Open database and see where player is currently located on the Y axis.
Check with map location and make sure no one or a wall is positioned in Y-1.
If no obstruction present, database updated for the Y value of the player - 1.
Read database for all areas the player could see at the moment and display them on the screen.

Problem was, it would take around a second for this to happen, making multiple simply impossible. I had my friend and I fighting each other in what looked and felt like slow motion. No lag or anything, just too slow for multiple player. You really need like .1 second frame rate at the minimum to play something online.

I have heard that there are special databases which are called "dynamic" ? I believe and can be used for multiple player gaming and fast response database calls in real time.

Am I going about this wrong? Any advice? Thank you so much!

Chris
#game #online #php #server
  • Profile picture of the author nxtgencreative
    If you goal is to have multiplayer in real time in the browser you need a few things and none of which involve php. The system will be composed of two components, a client and server. The client is simply on the browser and is created using silverlight, flash, java or javascript/html5. The server will be some application sitting on another computer that waits for calls to it from the clients. Clients and Servers communicate using things called sockets and pass information through sockets. The server would do the calculations for xyz and send the results back to the client. Usually multiple clients would connect to a single server and the server would hold the position of the clients. All the information held by the server would be held in the ram of the server for as quick as possible responses.

    The actual technicalities of how this whole exchange happens are a lot more in depth and vary for every game. If you want to learn more you might want to read up on multiplayer game development in general. A quick google search should get you started.

    Good luck to you.
    {{ DiscussionBoard.errors[3369412].message }}
  • Profile picture of the author Peter01
    A webhost like A Small Orange would suffice - because you can increase the hosting as and when you need to.
    {{ DiscussionBoard.errors[3369662].message }}
  • Profile picture of the author nxtgencreative
    Peter-Small Orange probably would not because you need to be able to run applications that take up a bit of resources. If one was to rent server for a game server they would need something like a virtual or dedicated hosting solution.

    Also chris check out XNA they have a lot of good examples about game dev and a few about game networking
    {{ DiscussionBoard.errors[3369960].message }}
  • Profile picture of the author nxtgencreative
    Also, you can have clients act like a server and have the server move from place to place. The reality is that any computer can be a server.
    {{ DiscussionBoard.errors[3369995].message }}
    • Profile picture of the author tirupati
      You can make use of Linux hosting.All the Linux supports PHP online games
      {{ DiscussionBoard.errors[3373384].message }}
  • Profile picture of the author myvps
    try to use VPS first.
    {{ DiscussionBoard.errors[3380748].message }}
  • Profile picture of the author Victor
    What about running your game in "the cloud"? Amazon has many services that you can use on an "as needed" basis. You can use services such as CloudFront and the S3 for storage. Scalability is all under your control in case you need more bandwidth / less bandwidth, etc.

    WS delivers reliable, scalable, and cost-effective compute and storage resources on which to host your online games. You can use the following AWS components alone or combined to build your scalable gaming application.

    Definitely worth looking into.
    {{ DiscussionBoard.errors[3408649].message }}
    • Profile picture of the author womki
      IMHO a php game is just like any other php script, what you need is a well coded script (mostly the part of db access), any normal dedicated server should run fine if it's well configured.
      {{ DiscussionBoard.errors[3409098].message }}
      • Profile picture of the author Tashi Mortier
        Okay a lot of discussion going on on this...

        Well there really is a problem with using PHP in the first place. Since you've got to see it this way there is a looong round-trip time on every request.

        You need to make a full HTTP request to send data and fetch data so you've got the original ping time * 2 + the time it takes to process the script * 2 in order to get a move from player 1 to player 2.

        You've got to poll the webserver very often in order to get a smooth gameplay and this can kill off nearly every server very quickly.

        I think that's why such games often use a dedicated server software that uses UDP which is much faster than TCP (used by HTTP). But if you want to continue using your PHP script try to optimize it as far as possible also you should use a hoster that has a PHP Opcode Cache (because that saves the time it takes to compile the PHP Script into code that the server's CPU understands).
        Signature

        Want to read my personal blog? Tashi Mortier

        {{ DiscussionBoard.errors[3409444].message }}
  • Profile picture of the author nxtgencreative
    Using Amazon cloud is a decent idea. With the cloud you can get access to gpus and cpus in addition to using faster languages like c++. As Tashi was saying TCP is much slower then UDP and should be used. Also PHP is slower then languages compiler to a machine language so PHP is not optimal.
    {{ DiscussionBoard.errors[3410399].message }}

Trending Topics