homepage Welcome to WebmasterWorld Guest from 54.166.108.167
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
Schoolbag




msg:1255142
 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!";

sleep(5);

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

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

thanks!

 

mogwai




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

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




msg:1255144
 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.

thanks!

coopster




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

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




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

Makes perfect sense, thanks!

jatar_k




msg:1255147
 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