fsockopen timed retry after error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

fsockopen timed retry after error

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Have you tried increasing

Code: Select all

stream_set_timeout(...)
Post Reply