Welcome to WebmasterWorld Guest from 54.147.44.93

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Pausing a script

     

Schoolbag

8:39 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Hi All,

Im trying to do the following, but the script sleeps and then runs.
------------------------------------------------------
echo "All Done!";

sleep(5);

header("location: [someplace.com...]
-------------------------------------------------------

Is there a correct way to do this without using HEADER redirects?

thanks!

mogwai

10:51 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Hi,

Not sure what you're trying to achieve here:

"but the script sleeps and then runs"

This is what you are telling it to do.

Are you trying to load the page then have it relocate after it has been displayed for 5 seconds? If so PHP is not your solution, use:

<META HTTP-EQUIV=Refresh CONTENT="5; URL=http://www.someplace.com/test">

Cheers

Schoolbag

1:15 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Hi and thank you for the reply,

Shouldnt the script run like this?:

echo "All Done!"; <---- prints to browser

sleep(5); <---- pauses the program

header("location: [someplace.com...] <--- then does


But, the script sleeps, and THEN it runs.

thanks!

coopster

1:44 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Schoolbag,

I'll give this a shot, but I'm not the best teacher ;)

The echo command is only going to print to the output buffer. Think of the output buffer as a place on the server's memory where you build your whole chunk of output stuff, including your normal HTML rendering statements. It doesn't actually get sent back to the browser until you tell it to when your script ends, PHP header() functions, etc. Therefore, writing *stuff* out via echo sits in the output buffer until this happens. Then you tell the server to sleep for a bit, and redirect with a header(). You're probably getting an error message too, correct?

You're message, "All Done!", is not going back to the browser. It is going to print the "All Done!" to the output buffer (not send it back to the user), sleep for 5 seconds, then redirect the browser to the location specified in your header function.

Try mogwai's suggestion to see if meets your desired results. You may also find the Output Control Functions [us3.php.net] to be a bit enlightening.

Schoolbag

1:48 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Makes perfect sense, thanks!

jatar_k

2:00 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Unless you are using output buffering
ie. ob_start() [ca.php.net]

then it should echo it straight to the browser. Then when you call header it should give you an error

"cannot send header info, output already started at line ..." or something like that.

I would go with mogwai's solution and use a meta refresh.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month