A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Speed of PHP and Multiplayer Games

  1. #1
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874

    Speed of PHP and Multiplayer Games

    I have made a small racing game, i want to have other players race with you but i dont want to have them all running collisions ect and being influenced by each other. In short i want to implament a ghost car system, the 2 players will both race at the same time on the same map together but the only thing that is being passed to each other is the x y and rotation of the other player.

    I will be sending out and reciving 3 veribles per frame, can i just store these in a txt file and edit it with php and still maintin any speed at all? Or do i have to go into the technical stuff with those server things?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  2. #2
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    First off, storing in a txt file isn't a good idea - you should use a database.

    But more importantly, http is pretty slow because of all the overhead (headers, non-persisant connections). So I would recommend working with XML-sockets. In that case php is almost out of the question (it IS possible to have a php script run on a server and listen to a port, but it's not its intended use so I don't know how stable this would be). So you'll either have to create your own server software for this or use one of the existing programs.

    That said, it's possible that php through http would suffice, but I think it would lag terribly.

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Usually running your own servers is not allowed by the host. If you have simple homepage then almost all hosts support php, but that is pretty much all they allow. Sockets and server programs are only good if you have full access to the server and no host allows that.

  4. #4
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    and no host allows that
    Sure they do! Just get a virtual private server, which is something between normal hosting and a dedicated server. It's like multiple servers running on the same hardware, and you have full root access to your virtual server.

  5. #5
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Fall_X, can i find one of those for free? Or at least, cheep?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  6. #6
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Nothing is for free. Sure, you can get some basic webspace for free, but that's always backed by advertising/marketing in some way. But a virtual private server, I wouldn't count on finding that for free.

    And cheap, that depends on your definition of cheap. I suppose you could find it for as little as $20 per month (possibly less), but I'm not sure if you'd get good support/uptime with that.

    Note that as far as I know, virtual private servers are a linux-only thing, so you'll have to know something about linux administration to install something on it. And about linux development in order to make your server software. I suggest you try doing it with Java.

    Also note that while I know what is involved in all this, I don't have hands-on experience with linux development, so I can't really help you beyond this.

  7. #7
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Ok cheers, so i guess i need to learn some java? Point to towards a link or, tell me what i should google?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  8. #8
    CostomJunky Xploder's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    635
    Quote Originally Posted by Gloo pot
    the 2 players will both race at the same time on the same map together but the only thing that is being passed to each other is the x y and rotation of the other player
    Gloo, the only thing, passing x,y and rotaion? That was my first approach with Electroserver3 but you must realize that, that would lag a lot. Your apprach must be to send the least amount and least frequent as possible. If the user is recieving constantly and the server is sending that's what creates lag. My second approach was send the staus of the user. That is whenever the status changes it is sent to the server the server relays that message to all other users. Each user has a "moving players" array and users that don't move are poped out, but if they move they're pushed back in. The last thing you must know is that still doesn't solve the problem of lag, you must use timebased movement to solve this. Even if one user runs your game on garbadge and someone on a core2extreme machine , all users must be reduced to garbadge, or you must kick the user if his fps falls too much.
    Hope that helps .

    Quote Originally Posted by Gloo pot
    Fall_X, can i find one of those for free? Or at least, cheep?
    You can always have a look at the good old Grand Multiplayer Thread: http://board.flashkit.com/board/show...&page=10&pp=20
    jobemjobem reviews some of the servers, one of which is free, I also tried Palabre and SmartFoxLite, but prefer Electroserver3.
    Last edited by Xploder; 08-28-2006 at 11:38 AM.

  9. #9
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    By the way, the best way to do multiplayer with minimum lag is, in my experience (which is rather limited), using splines to predict player's locations based on their previous location and movement.

    Note that I only experimented with this years ago, using Blitz3D, so I can't really give you any examples. I barely even remember how it works. But this article might be able to help : http://www.gamedev.net/reference/art...article914.asp

  10. #10
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    Hey Gloo pot, I just sent you a PM about a really great virtual private server host you might be interested in.

  11. #11
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Thanks for that PM Flashisland, looks nice and is cheep as chips... Maby now is the time to pay for web hosting....

    So from what i understand, I cant have any multiplayer games unless i have a webhost that alows me to have full access to what ever needs to be accessed. And there is no other decent way of doing it?
    Gloo, the only thing, passing x,y and rotaion? That was my first approach with Electroserver3 but you must realize that, that would lag a lot
    Max 3 chars per varible x 6 (3 per player).. 18 chars all up, 1 byte of data per char = 18bytes sent 15 times is about 3kbs every second? Im shore dialup could handle that and most people are going to broadband (If i have calculated that wrong correct me)? I could always drop it back, its just to show where the other car is so it doesnt have to be exact. The whole game is time based so i would just need to set it up to make the race start at the same time on each computer and know exactly when each car passed the finishes...

    Anyhoo, thanks for ya help ima go do some googleing and work on my game some more.
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  12. #12
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I would say for your game even simplest php can handle it. So what if it other cars are not shown in completely real time, you can still play it.

  13. #13
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    I would say for your game even simplest php can handle it. So what if it other cars are not shown in completely real time, you can still play it.
    Thats what i thought, it doesnt need to be the exact location, as long as at the start of the race i can make shore both start exactly on time and i can tell who finished first. Other than that i dont car if it only updates the other player every 3 seconds as long as you have some idication the other player is there and racing.

    Should i use a txt file or just store the varibles in a array in php and just change varibles? I would think varibles would be much faster...
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  14. #14
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I am no php expert, but i think you can loop the php script as long the game is running and store the variables in memory. When both players have finished or no player sends any data for 30 seconds, end the script.

  15. #15
    Senior Member
    Join Date
    Aug 2002
    Posts
    349
    Theres an OLD script i posted here using php sockets for multi user applications.

    you DO NOT need full access to the server to run php sockets (which is nice for cheap hosting) the host needs to have the sockets extensions enabled.
    Free Flash Multiplayer Gaming
    http://www.gecko-games.com

  16. #16
    Junior Member
    Join Date
    Sep 2006
    Posts
    1
    I'm making a multiplayer asteroidesque game and I used the XML socket stuff and a python script to do mine.

    To increase speed what I tried to do was only send the velocities and rotation of the ships whenever either of those variables were changed and then have the client do the work of positioning the ship however I ended up getting ships on one side of the screen while their lasers were on the other.

    After that I changed it so that x,y,velocities, and rotation are sent so that whenever the velocity of the ship is changed the x and y is sent too so as to reposition the ship. So far the only trouble I have had is that if its slow the other ships sort of jump around.

    I'll be happy to send code of watever part you want.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center