Jump to content

llHTTPRequest/Response - Timeout


You are about to reply to a thread that has been inactive for 3605 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi All,

 

As I further my understanding of how to communicate with PHP script out-world, a comment in the wiki on llHTTPRequest() has me wondering. One of the Caveats says:

'Requests must fully complete after 60 seconds, or else the response will be thrown away and the http_response status code will be 499'

Now in an example where a PHP script will be sending back multiple lines of data, and so triggering multiple http_response() event handlers (see post Access file on Web Server Help - Noob Question, what I am wondering  is if the 60 seconds means from the time the initital Request is made (which I believe it is) or if the 'clock' is reset on each response. Basically wondering if I should be making a request for each line of data needed (see following) or the code as described in the earlier post will work till the end of the file independent of how long it is.

 

key http_request_id;
string INFO_URL = "http:\\my_domain.com\info_retriever.php";
string END_FILE = "eof"
 
state read_webfile
{
    state_entry()
    {
        http_request_id = llHTTPRequest(INFO_URL, [HTTP_METHOD,"POST",HTTP_MIMETYPE,"text/html; charset=iso-8859-1"], "line=0"));
    }
 
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == http_request_id)
        {
             if (body != END_FILE)
             {
                  //do something with textline from body
                  
                  //Now Call the PHP again, passing the line we were in that came in body
                  http_request_id = llHTTPRequest(INFO_URL, [HTTP_METHOD,"POST",HTTP_MIMETYPE,"text/html; charset=iso-8859-1"], "line=" + (string)lineNum );

             }
             else
             {
                  state running;
             }
        }
    }
}

 

Link to comment
Share on other sites

Basically, an HTTP conversation consists of one request and one response. The fact that the requested php file may contain several echo commands (or echo commands in a loop), does nor mean several responses are give (and several http_response events are triggered). All echoed text form one response.

if, in your example, the amount of text in the text file is (or can be) too long (which is more likely than the php taking too long to read the file), in each response, read one line and then trigger fire a new request until the response contains something telling you that reading the file has reached the end. You actually do that in your sample script: you trigger a new request inside the response. In combination with the php in the other thread woul result in an endless loop - the php would return the complete contents of the file each time.

If you run into the problem, that the file is actually too long to be read in 60 seconds, you should consider using a database that contains the bits of information you want to send to SL.

Link to comment
Share on other sites

Thanks Darkie,

 

Clear on the endless loop, it was a long day yesterday and only was not able to put the full idea into script as my brain was a bit fried. So. while you have cleared some up, this leads to other questions:

If this is the PHP running on the server that will respond to the llHTTPRequest from SL:

<?php$handle = @fopen("/info/infofile.txt", "r");if ($handle) {    while (($buffer = fgets($handle)) !== false) {        echo $buffer;    }       if (!feof($handle)) {        echo "Error: unexpected fgets() fail\n";    }    else    {        echo "eof\n";    }        fclose($handle);}?>

 

And so it reads line by line the file, echoing each line. So my questions are:

  1. When does it know to finish this and send it to SL? Can I force a send, and thus an http_reponse() event handler in SL?
  2. When I receive the multi-line string in the http_response() event handler, what do I need to parse the string passed as body to break the string into its constituent lines?

 

Link to comment
Share on other sites

As soon as the script finishes, it closes the communication. You can of course include failure handlers in your script and you should. You already have one for an unexpected end of the file reading. If the execution of the php fails, you'll get a time out or an 499 error.

As for the parsing you add separator to the string in php (| is a good one). In LSL, llString2List can be used to parse the string into a list of substrings

Link to comment
Share on other sites

Ok .. thanks for the response Darkie. So just to be clear, each call to echo just adds the text onto the return that SL will receive .. thus:

 

echo("This");echo("return started");echo("as 3 lines");

 would give SL an body value in the return of "Thisreturn startedas 3 lines". And so I need to add my own end-of-line sperator if I want to get the individual lines in the return.

 

Still not clear if there is a way to push a response back from PHP to SL, causubg the http_response() event handler to fire, withou actually ended my code in PHP:

//Code that does some stuff in PHP, say read from a file

//Code that returns the results to SL

//Some other code that runs doing other things

 

Link to comment
Share on other sites

Simply speaking, a php file executes and then closes he HTTP connection - that's what it is made for. The execution is quite fast (usually), so that there is no need to do things after you send the response.

There are however ways to let a php file call another php script or some other kind of command - but this can be a bit tricky. One example to do that can be found here.

Another trick that is used to evade the timeout problem (e.g. if you are grabbing a large amount of data and write it to a database or if you want to write the contents of a database to a flat file) is to call a php file over and over again till the task is done.

In general, you should execute all you want to do as part of the response.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3605 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...