Sleep asynchronous?

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

    Sleep asynchronous?

    I wanted have this as part of a flood control script:
    <?
    echo ("Flood control in place - please wait " . $floodinterval . " seconds
    between postings.");

    sleep(5);
    // go back two pages
    echo "<script>window .history.go(-2);</script>";
    exit;
    ?>

    Problem is that the first echo never shows up on the page; it displays a blank
    page (well, the page constructed up to PHP section), then sleeps for the five
    seconds and goes back two pages.

    Why?

    Thanks -

    jon

    --
    jwayne@_myrealb ox_no_spam.com
  • Jason Dumler

    #2
    Re: Sleep asynchronous?

    JW wrote:[color=blue]
    > I wanted have this as part of a flood control script:
    > <?
    > echo ("Flood control in place - please wait " . $floodinterval . " seconds
    > between postings.");
    >
    > sleep(5);
    > // go back two pages
    > echo "<script>window .history.go(-2);</script>";
    > exit;
    > ?>
    >
    > Problem is that the first echo never shows up on the page; it displays a blank
    > page (well, the page constructed up to PHP section), then sleeps for the five
    > seconds and goes back two pages.
    >
    > Why?[/color]

    Could be caching is turned on with your web server. So you're spitting
    out the notice, but the server is holding all your output until the
    script is done. In which case the browser gets the <script> and
    executes it right away, before you can see the notice posted on the page.

    You could have the script execute with a

    <script language="javas cript">
    window.setTimeo ut('window.hist ory.go(-2);', 5000);
    </script>

    which will tell the browser to wait 5 seconds before going back. Even
    if caching is turned on, this should work.

    Jason

    Comment

    • JW

      #3
      Re: Sleep asynchronous?

      Jason Dumler <dumlerjason_bu gger_spam@netsc ape.net> wrote:
      [color=blue]
      >JW wrote:[color=green]
      >> I wanted have this as part of a flood control script:
      >> <?
      >> echo ("Flood control in place - please wait " . $floodinterval . " seconds
      >> between postings.");
      >>
      >> sleep(5);
      >> // go back two pages
      >> echo "<script>window .history.go(-2);</script>";
      >> exit;
      >> ?>
      >>
      >> Problem is that the first echo never shows up on the page; it displays a blank
      >> page (well, the page constructed up to PHP section), then sleeps for the five
      >> seconds and goes back two pages.
      >>
      >> Why?[/color]
      >
      >Could be caching is turned on with your web server. So you're spitting
      >out the notice, but the server is holding all your output until the
      >script is done. In which case the browser gets the <script> and
      >executes it right away, before you can see the notice posted on the page.
      >
      >You could have the script execute with a
      >
      ><script language="javas cript">
      >window.setTime out('window.his tory.go(-2);', 5000);
      ></script>
      >
      >which will tell the browser to wait 5 seconds before going back. Even
      >if caching is turned on, this should work.[/color]


      Worked like a charm! Thanks much...

      jon
      --
      jwayne@_myrealb ox_no_spam.com

      Comment

      Working...