Page 1 of 1

fsockopen timed retry after error

Posted: Fri Nov 10, 2006 8:12 am
by amir
I have a small script that checks via fsockopen the Brazilian postal services website, checking for a shipping quote for online stores.
The problem is, their server is frequently returning time out errors on connection, thus leaving me without any quotes.

I thought about automatically making 2 or 3 new requests after, say 5 seconds. If the retries can't be succeeded, then give a "No quote avaliable at this time, try again later" to the customer.

As it is now, the "no quote" msg is returned in the first call. The code is as below:

Code: Select all

$conexao = fsockopen("www.correios.com.br", 80, $errno, $errstr, 30);
    if (!$conexao) {
     //echo "$errstr ($errno)<br />\n";
     echo 'No connection available. Try again later.'; // This is the msg I don't want to show 
     return false;
    } else {
      //  process quote here
    }
Thanks

Posted: Fri Nov 10, 2006 12:06 pm
by John Cartwright
Have you tried increasing

Code: Select all

stream_set_timeout(...)