1

I am making a simple PHP and JavaScript multiplayer game. Here is a quick rundown of how it will work: when a user does something, it is submitted with ajax to a php script, which saves a few charachters representing the action taken to a text file on the server. Every so often (to be exact, 430 milliseconds), the other player's computer submits something to another php script, which checks for new content on that text file. If there is new content, it is returned to the client-side and displayed on the other users screen. The only thing is, I am new to ajax, php, and anything server and do not want to crash the server. To make sure I do not crash the server, I need to know if submitting an XMLHttpRequest every 430 millisecoinds is a potential cause of major server strain. Not only that, but BOTH players will submit an XMLHttpRequest every 430 milliseconds. I can easily raise it to 450 milliseconds, but anything beyond that will be a problem.

markasoftware
  • 10,714
  • 7
  • 36
  • 62

2 Answers2

1

Well, that depends entirely on your server. If you're running it on a ZX80, I'd be concerned :-)

However, that's only four to six requests a second and modern servers should have no difficulty handling that sort of load.

Of course, if what happens on the server in response to your requests takes more time that the cycle time, you'll run into problems, especially with sustained traffic (no chance to slow down).

paxdiablo
  • 772,407
  • 210
  • 1,477
  • 1,841
  • This really helps! 430 milliseconds is actually about 2 times per second, so I am fine. I have no idea what a ZX80 is. – markasoftware Feb 26 '12 at 03:34
  • Sorry, @Markasoftware, showing my age - I may as well have mentioned eight-track tapes or Betamax :-) The ZX80 was a very early computer, famous for lack of resources. It's 1K of RAM was shared between program memory and display (which was a sequential "file" with newlines, to the point where making your program too big meant you lost some of the screen :-) – paxdiablo Feb 26 '12 at 03:36
  • In addition, it is 2-3 times as you say, I doubled that since you stated two machines would be doing it. – paxdiablo Feb 26 '12 at 03:37
  • Now I get it. I believe I have a quite average server, and my game should work. – markasoftware Feb 26 '12 at 04:03
  • About the response time, I already calculated it to take 50 milliseconds on average for that, so I said 430 to allow slower internet connections to work as well. – markasoftware Feb 26 '12 at 05:05
  • Now I have another related question: what if two sets of players were playing? or three? Would the server hold it? My main question is: how many requests can an average server take per second? – markasoftware Feb 28 '12 at 01:26
  • @Markasoftware, I've seen test runs on Apache range between 330 requests/sec on a 1.6GHz single-core, up to 2100 requests/sec on an octocore grunt machine. But, again, it depends totally on what you're doing with the requests. Might I suggest you have a look over at serverfault.com - a better answer is probably available there and, if not, you can ask this question there. Those bods over there are more targeted towards these sort of questions than SO. – paxdiablo Feb 28 '12 at 01:37
1

This will be inefficient with separate requests, I would suggest taking some time to understand COMET, the term refers to a number of techniques to manage always open bi-direction connections over HTTP.

Here are some useful links I'd start with (I'm not too familiar with COMET for PHP, so I haven't vetted these resource recommendations myself).

http://en.wikipedia.org/wiki/Comet_%28programming%29

Using comet with PHP?

http://www.zeitoun.net/articles/comet_and_php/start

Community
  • 1
  • 1
David Parks
  • 25,796
  • 41
  • 148
  • 265
  • Thanks, but I know completely how to use Comet already but the only problem with that is that I do not now any thing in PHP that is like the JavaScript SetInterval (it does a function every set number of milliseconds), so the php would be check the text document again as soon as it was done the first time, which is even worse than an XMLHttpRequest every 430 ms. Thanks anyway! – markasoftware Feb 26 '12 at 03:32