Is there a way to send updates from PHP to flash in the middle of a request?
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 (开发者_StackOverflow社区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!
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.
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.
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));
}
精彩评论