Can't get timeout to work with fsockopen

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DesignGuy

    Can't get timeout to work with fsockopen

    I'm trying to get a script to timeout if the server is under heavy load or
    otherwise unavailable. Eventually, this will try different mirrored domains
    as each one times out. But at the moment I can't even get a single domain to
    timeout:


    $fp = fsockopen("www. example.com", 80, $errno, $errstr, 2);
    if(!$fp) {
    echo "Unable to open\n";
    } else {
    fputs($fp, "GET / HTTP/1.0\n\n");
    $start = time();
    socket_set_time out($fp, 2);
    $res = fread($fp, 20000);
    var_dump(stream _get_meta_data( $fp));
    fclose($fp);
    print $res;
    }


    Is there an override setting in the PHP ini file or something wrong in the
    code above?

    Thanks in advance



  • Jochen Daum

    #2
    Re: Can't get timeout to work with fsockopen

    Hi designGuy!

    On Wed, 03 Sep 2003 04:48:25 GMT, "DesignGuy" <dontbother@now here.com>
    wrote:
    [color=blue]
    >I'm trying to get a script to timeout if the server is under heavy load or
    >otherwise unavailable. Eventually, this will try different mirrored domains
    >as each one times out. But at the moment I can't even get a single domain to
    >timeout:
    >
    >
    >$fp = fsockopen("www. example.com", 80, $errno, $errstr, 2);[/color]

    (...)

    I did something similar quite a while ago and discovered that the
    socket functions are full of bugs, which are not solved yet. I had
    another contact with them on something else some weeks ago and it
    looked the same. Have a look at bugs.php.net yourself.

    I don't know how it does it, but maybe you can use

    Snoopy on Sourceforge or
    curl_* functions

    HTH, Jochen
    --
    Jochen Daum - CANS Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    • DesignGuy

      #3
      Re: Can't get timeout to work with fsockopen

      > I did something similar quite a while ago and discovered that the[color=blue]
      > socket functions are full of bugs, which are not solved yet. I had
      > another contact with them on something else some weeks ago and it
      > looked the same. Have a look at bugs.php.net yourself.[/color]

      Hi,

      After looking around I got the same impression.... I'll keep looking and
      check into your suggestions.

      Thanks!



      Comment

      Working...