0
votes

Background: I've been drafted to maintain and update a flash/flex/as3 front-end to website using php on the backend. I'm getting better at it, but I'm still new to the environment.

I need some processed information received back in the return handler of a POST. I thought it would be clever to do the next POST within the return handler. In other words, I've got something like this:

private function finishThis():void
{
    var s:HTTPService = new HTTPService();
    rq.action = "do_something";
    s.url = "inc/php/test.php";
    s.method = "POST";
    s.request = rq;
    s.requestTimeout = 120000;
    s.addEventListener(ResultEvent.RESULT, doSomethingRH);
    s.send();
    s.disconnect();  // That's a test, it didn't help
}

and then in doSomethingRH(), I've got

private function doSomethingRH(event:ResultEvent):void
{
    doSomethingElse();
}

private function doSomethingElse():void
{
    var s:HTTPService = new HTTPService();
    rq.action = "do_something_else";
    s.url = "inc/php/test.php";
    s.method = "POST";
    s.request = rq;
    s.requestTimeout = 120000;
    s.addEventListener(ResultEvent.RESULT, doSomethingElseRH);
    s.send();
    s.disconnect();  // That's new, it wasn't there before
}

All of this works as expected using http://localhost (WAMP). But online, though I have backend indications that function do_something_else runs (so far), but function doSomethingElseRH() never gets called. Instead, I get the error I've seen from several posts :

[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2

text="Error #2032: Stream Error. URL: http://test.net/inc/php/test.php"].
URL: http://test.net/inc/php/test.php"]

The problem pointed out most often is too many simultaneous connections. I don't need to do multiple connections, but thought perhaps I had them since I was starting the new POST in the previous POST return handler. Instead of calling doSomethingElse() directly, I added an event and did a dispatchEvent() to call it, but at least according to the call stack shown in FlashDevelop, the eventual call to doSomethingElse() was under the doSomethingRH() function (still learning this stuff). And all of that is conjecture based on a post I saw about getting the HTTPService instance from within event delivered to the return handler.

My ultimate question is, how can I achieve sequential POSTs like this without the error?

And if I'm getting the error because of the way I'm chaining them together, is there a clean-up function I can do so that when the return handler is called, the connection can be fully closed?

Update - it's fine

A pdf engine was being called within both functions, one to create a base file, the other to append some pages. It was working fine, but was updated recently. Blocking those activities allowed the http flow to work as expected, no disconnect() needed.

The best I can say for this is it's an example of chaining calls together that I haven't seen online, I suppose that's something.

2
Stream Error means "file not found". So on your server test.net make sure there exists a folder called inc with sub-folder php and in that sub-folder you put the test.php. Also some servers have a specific folder for running PHP scripts from, so check that your file is in right place...VC.One
The error can mean that, but as I explained the first call works, the second call works, both to the same URL. It's only the completion of the second call that fails.trueskew
Are you sure your server settings are not preventing multiple quick requests to same file? I mean why would same file be accessible one time but then become "file not found" a few milliseconds later?VC.One
It's a public, busy server so I can't imagine that the server would prevent it. The second call is definitely executing to completion, it's the return status on the flash side that's complaining, so I'm not convinced that it's a "file not found" error, despite the implication of the error code.trueskew

2 Answers

1
votes

It's possible that you s.disconnect(); too soon (hence PHP file is not found). Why disconnect immediately after .send before that even gets a chance to do anything? File access on hard drive is faster than between web server. If still failing then try adding a delay (ie: disconnect, then start a timer that counts to 3 seconds) before attempting to do doSomethingElse();...

Untested but try :

public var s:HTTPService; //make one and re-use 

private function finishThis():void
{
    s = new HTTPService();
    rq.action = "do_something";
    s.url = "inc/php/test.php";
    s.method = "POST";
    s.request = rq;
    s.requestTimeout = 120000;
    s.addEventListener(ResultEvent.RESULT, doSomethingRH);
    s.send();

}

...then in doSomethingRH() :

private function doSomethingRH(event:ResultEvent):void
{
    s.disconnect(); //is now finished so disconnect before re-use
    doSomethingElse();
}

private function doSomethingElse():void
{
    s = new HTTPService();
    rq.action = "do_something_else";
    s.url = "inc/php/test.php";
    s.method = "POST";
    s.request = rq;
    s.requestTimeout = 120000;
    s.addEventListener(ResultEvent.RESULT, doSomethingElseRH);
    s.send();

}
0
votes
  • h t t p should be http
  • relative urls are relative to where the swf is loaded from... i would have a baseUrl variable that you want to be the relative url