By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

Sleep asynchronous?

P: n/a
JW
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@_myrealbox_no_spam.com
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
JW wrote:
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?


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="javascript">
window.setTimeout('window.history.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

Jul 16 '05 #2

P: n/a
JW
Jason Dumler <du*********************@netscape.net> wrote:
JW wrote:
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?


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="javascript">
window.setTimeout('window.history.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.

Worked like a charm! Thanks much...

jon
--
jwayne@_myrealbox_no_spam.com
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.