1

Is there a way make an HTTP request from within JavaScript to a URL that will, over time, produce multiple JSON responses and then process those JSON response as they are received by the client?

What I want to do is, in PHP on the server, test a series of Flash streams, to ensure they are serving data and then communicate the updates of that test as a series of sequential JSON updates that would be received and decoded by JavaScript and then update the DOM as the updates comes in. The key part is that the client would be process and display the updates as they come in (the test takes a while to complete) and not wait for the socket to close before processing the updates.

Edmond Meinfelder
  • 313
  • 1
  • 5
  • 19

2 Answers2

3

See:

http://socket.io/

http://dev.w3.org/html5/websockets/

How do I implement basic "Long Polling"?

Community
  • 1
  • 1
Jamie Wong
  • 18,104
  • 8
  • 63
  • 81
1

what you want is a socket stream connection. but thats not how http works. you will have to work around this.

you could write 2 php scripts on the server, the main script is testing your flash streams and storing the info in session, and the 2nd script is checking the sessions for new results and returns them in JSON. on the client side have another javascript that preiodically polls the 2nd php script for new results and display them.

does the flash stream checking have to be sequentially? like, can you only check one flash stream at a time?

at0mzk
  • 1,884
  • 14
  • 17
  • The session-based answer is what I came up with, but my manager is swearing this is trivial and does not require persistence. I test the Flash streams using the PHP socket API in parallel using select. I use PHP, because, on the server, I need to make a query to figure out what hosts to check. – Edmond Meinfelder Feb 18 '11 at 02:52
  • in this sense php session is not persistence but rather inter process communication. Maybe that argument helps with your manager ;) – at0mzk Feb 18 '11 at 03:14
  • You could also insert the info of the streams to test into the javascript and hava javascript iterate over all streams to test. then the stream testing script on the server would only test one stream at a time and return results directly, no inter process communication needed. – at0mzk Feb 18 '11 at 03:16