PDA

View Full Version : php timer


djew3001
06-08-03, 03:58 AM
hi!

i need a function to make a countdown when a users reach my php webpage... After 30 seconds it will echo a string! and after an other 30 seconds, it will echo an other string! How do I proceed ?

thx :D

DuEy
06-08-03, 05:09 AM
echo "hey welcome to my site";
sleep(30);
echo "hows the wait";
sleep(30);
echo "dam servers so slow we will be with you soon";
sleep(30);
echo "sorry for the wait how can i help you?";


next time post in the PHP forum =)

Daniel Bahl
06-08-03, 08:44 AM
DuEy ;) You took the answer straigh from my mouth :D

Keep up the good work

Daniel Bahl
06-08-03, 08:45 AM
BTW. Welcome to the board djew3001, hope you will get a great time here, together with us ;)

best regards
daniel bahl

Aftek
08-14-06, 01:05 AM
Does not work for me =/

if i use

echo "hey welcome to my site";
sleep(30);
echo "hows the wait";
sleep(30);
echo "dam servers so slow we will be with you soon";
sleep(30);
echo "sorry for the wait how can i help you?";


with 30sec each time,
browser says respond time too long...

if i use it with 1-3 sec... then the page will show,
but all at once after the total amount of sleep...
why =/

mab
08-14-06, 02:57 AM
The reason for no output until the script terminates/faults is due to buffering, probably either the web server you are on or the browser you are using. See the information at this link - http://www.php.net/manual/en/function.flush.php

This buffering/flush is separate from the output buffering (ob_start/ob_end_flush) that PHP can do.

Basically, the output is not sent to the browser and/or displayed by the browser until the script completes (or faults.) The default maximum execution time for a PHP script is 30 seconds (which you should receive an error message for if you try the following code.)

Try the following code to see what is going on -
<?php
error_reporting(E_ALL);
echo "hey welcome to my site<br />";
flush();
sleep(30);
echo "hows the wait<br />";
flush();
sleep(30);
echo "dam servers so slow we will be with you soon<br />";
flush();
sleep(30);
echo "sorry for the wait how can i help you?<br />";
?>

Christian
08-14-06, 01:05 PM
Moved to PHP. :)

Aftek
08-14-06, 01:41 PM
this is what i get when using flush() :

"
hey welcome to my site
hows the wait

Fatal error: Maximum execution time of 60 seconds exceeded in ..\index.php on line 9
"

both IE and FireFox..
at least now he prints what has been flushed before the time runs out...
but still print out all at the end.

I'm using Apache 2.2.2 with PHP 5.1.4 and the connector from apachelounge...

Keith
08-14-06, 02:05 PM
PHP has a default of 30 seconds for script execution before it dies (looks like yours is set to 60). It has nothing to do with what browser you're using.

If you sleep() the script 5+ times at 30 seconds each, it will by far exceed that limit. That's why the first two are fine before the error is thrown.

Put this at the top of your page:
set_time_limit( 0 );

That will allow the script to execute forever without timing out.

Aftek
08-14-06, 02:16 PM
Thanks Keith... set_time_limit got rid of the error.. so now at the end of total amount of sleep in script everything prints out...
but still only at the end =/


im looking for somehting like this too hehe :
hi!

i need a function to make a countdown when a users reach my php webpage... After 30 seconds it will echo a string! and after an other 30 seconds, it will echo an other string! How do I proceed ?

thx :D

tangazacom
08-15-06, 05:03 AM
Keith notes are right, php has max_execution_time, max_input_time, you just have to check your php core config using phpinfo(); you wll see.

Cheers

conclusion
08-16-06, 06:24 PM
welcome to this board