is stream_set_timeout cumalitive?

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

    is stream_set_timeout cumalitive?

    Say I set the stream timeout to 5 seconds with stream_set_time out, call
    fwrites, which takes 2 seconds, and then call fgets, which takes
    another 2 seconds. Would a subsequent call to fwrite timeout in 1
    second or in 5?

    I'd test it out myself, if I knew how to make stuff take 2 seconds to
    load, but alas - I don't.

  • yawnmoth

    #2
    Re: is stream_set_time out cumalitive?


    yawnmoth wrote:[color=blue]
    > Say I set the stream timeout to 5 seconds with stream_set_time out, call
    > fwrites, which takes 2 seconds, and then call fgets, which takes
    > another 2 seconds. Would a subsequent call to fwrite timeout in 1
    > second or in 5?
    >
    > I'd test it out myself, if I knew how to make stuff take 2 seconds to
    > load, but alas - I don't.[/color]

    Well... I wrote two scripts that I thought would test this, but
    unfortunately, the only thing they seem to prove is that I don't have a
    clue as to what I'm doing.

    Here's the script we're trying to read - test.php:

    <?
    sleep(2);
    echo "testing\r\ n";
    flush();
    sleep(2);
    echo "more testing\r\n";
    flush();
    sleep(2);
    echo "even more testing\r\n";
    ?>

    Here's the script that's doing the reading - read.php:

    <?
    $path = 'http://www.domain.tld/test.php';

    $hostname = preg_replace('#http://([^/]*)/.*#','$1',$path );
    $short_path = preg_replace('# http://[^/]*(/.*)#','$1',$pat h);

    $start = time();
    $fsock = fsockopen("tcp://$hostname", 80, $errno, $errstr, 1) or
    exit("Failed: $errno - $errstr");
    socket_set_time out($fsock,5);

    fputs($fsock,"G ET $short_path HTTP/1.1\r\nHost:
    $hostname\r\nCo nnection: close\r\n\r\n") ; // works
    echo fgets($fsock,10 24);
    echo "<br />fgets #1 ran at ".(time()-$start)." seconds<br />";
    echo fgets($fsock,10 24);
    echo "<br />fgets #2 ran at ".(time()-$start)." seconds<br />";
    echo fgets($fsock,10 24);
    echo "<br />fgets #3 ran at ".(time()-$start)." seconds<br />";
    exit;
    ?>

    When test.php is loaded in Firefox, it takes about six seconds. The
    first two seconds witeness the output of "testing", the next two
    seconds yield "more testing", etc.

    When test.php is loaded with read.php, however, it seems to take just
    two seconds. The output is this:

    HTTP/1.1 200 OK
    fgets #1 ran at 2 seconds
    ....
    fgets #2 ran at 2 seconds
    ....
    fgets #3 ran at 2 seconds

    What I'd expect is something more like...

    HTTP/1.1 200 OK
    fgets #1 ran at 2 seconds
    ....
    fgets #2 ran at 4 seconds
    ....
    fgets #3 ran at ? seconds

    Unfortunately, this isn't happening. Any ideas as to why would be
    appreciated.

    Comment

    • Chung Leong

      #3
      Re: is stream_set_time out cumalitive?

      The answer is no.

      Comment

      • TerraFrost

        #4
        Re: is stream_set_time out cumalitive?


        Chung Leong wrote:[color=blue]
        > The answer is no.[/color]

        No, it'd take 1 second, or no, it'd take 5?

        Comment

        Working...