0

I have a PHP process that does a bunch of stuff and I want to send feedback to the Flash client that calls it, as the request is being processed. However, since I'm listening for the COMPLETED event, I don't get the feedback until the PHP completes execution (at which time all the buffered messages arrive at once).

I tried using the PROGRESS event but that seems not to work (unless I'm not using it right).

Is there something to this on the PHP side that I may be missing? Or is Flash simply not designed to get updates from the server in a regular URLRequest... I can use a socket for this, but I would much rather not have to!

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236

3 Answers3

2

Depends on what you are asking PHP to do on the backend. If you are sending json or xml data you could always call flush to send the current output buffer to the client on a more frequent basis.

Wes
  • 6,455
  • 3
  • 22
  • 26
2

Have you tried using the PROGRESS event while using PHP's flush() function to send output periodically, rather than when the PHP script finishes execution.

d.syph.3r
  • 2,215
  • 1
  • 19
  • 14
  • actually... I think I gave the green checkmark prematurely. The PROGRESS with the flush does provoke an event, but there is no data that is returned. I think this may be a php issue, though the docs do seem to indicate that the progress event isn't designed to return back data... rather just a byte size. – Yevgeny Simkin Apr 20 '11 at 18:50
1

It can be done. Key is flash.net.URLStream. I'm using it this way, (code is not complete but I think you get the picture):

var stream:URLStream = new URLStream();
var request:URLRequest = new URLRequest("yourUnbufferedPHPURLhere?rand="+Math.random());
stream.addEventListener(ProgressEvent.PROGRESS, progressHandler);
stream.load(request);
function progressHandler(event:Event):void{
    trace("PROGRESS: "+stream.readUTFBytes(stream.bytesAvailable));
}
Breign
  • 146
  • 8