homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Pausing a script

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

Hi All,

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


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

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




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


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">



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

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.



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


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.


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

Makes perfect sense, thanks!


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

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved