0

What i'm working on is a chat, so i want a database read/display every 1 second and also by submitting a new message. I figured my httprequest doesn't work (doesn't get past readystate 1) because i trigger a new request while an old one isn't finished. Firebug says each request takes more than 1 second:

GET h**p://localhost/php2/projekt/open_blog/load.php 200 OK 1.03s

If i set the interval of the requesting function higher than the needed 1 second to answer it works, but that can't be it. On another machine this happenend instantaneously. I'm running it on xampp anyway. Is this some php.ini setting i am missing? How would that work out on an actual online server?

And why can't several request happen at the same time anyway? The object is inside a function, so every one is a new unique one.

br4nnigan
  • 646
  • 6
  • 13
  • For a chat, you might want to look into Long polling/Comet. http://en.wikipedia.org/wiki/Comet_%28programming%29 And maybe you want to consider using XMPP (http://de.wikipedia.org/wiki/Extensible_Messaging_and_Presence_Protocol) for an out-of-the-box solution. – lethal-guitar Jan 19 '13 at 20:27
  • You **can** make several requests at the same time, [but not as many as you might want](http://www.browserscope.org/?category=network). – h2ooooooo Jan 19 '13 at 20:30

1 Answers1

0

Don't make a new request until the first one is finished. It's entirely possible for a request to take a second, or 5.

You might also look at something like Socket.IO which uses Websockets, or emulates them when needed.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Ok i'm hitting the limit of what i can do with my current technology. That's what i needed to know. I was just wondering because on another machine with the same setup the requests were instantanious. – br4nnigan Jan 19 '13 at 20:48
  • @lazbrannigan, There are lots of factors that come into play. In any case, you can't assume that users of your system will get responses so quickly. – Brad Jan 19 '13 at 20:49