Current location: Hot Scripts Forums » Programming Languages » PHP » php timer


php timer

Reply
  #1 (permalink)  
Old 06-08-03, 02:58 AM
djew3001 djew3001 is offline
New Member
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
php timer

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
Reply With Quote
  #2 (permalink)  
Old 06-08-03, 04:09 AM
DuEy's Avatar
DuEy DuEy is offline
PHP is my life.
 
Join Date: Jun 2003
Location: New Zealand
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

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 =)
__________________
-Duey
server: irc.chatchannel.org
channel: #hotscripts
Reply With Quote
  #3 (permalink)  
Old 06-08-03, 07:44 AM
Daniel Bahl's Avatar
Daniel Bahl Daniel Bahl is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Denmark (City: Haslev)
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
DuEy You took the answer straigh from my mouth

Keep up the good work
__________________
Why don't share your knowledge?!
Reply With Quote
  #4 (permalink)  
Old 06-08-03, 07:45 AM
Daniel Bahl's Avatar
Daniel Bahl Daniel Bahl is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Denmark (City: Haslev)
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
BTW. Welcome to the board djew3001, hope you will get a great time here, together with us

best regards
daniel bahl
__________________
Why don't share your knowledge?!
Reply With Quote
  #5 (permalink)  
Old 08-14-06, 12:05 AM
Aftek Aftek is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Does not work for me =/

if i use
PHP Code:

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 =/
Reply With Quote
  #6 (permalink)  
Old 08-14-06, 01:57 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
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 Code:

<?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 />";  
?>
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #7 (permalink)  
Old 08-14-06, 12:05 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Moved to PHP.
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Reply With Quote
  #8 (permalink)  
Old 08-14-06, 12:41 PM
Aftek Aftek is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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...
Reply With Quote
  #9 (permalink)  
Old 08-14-06, 01:05 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
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:
PHP Code:

set_time_limit); 

That will allow the script to execute forever without timing out.
__________________
The toxic ZCE

Last edited by Keith; 08-14-06 at 01:37 PM.
Reply With Quote
  #10 (permalink)  
Old 08-14-06, 01:16 PM
Aftek Aftek is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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 :
Quote:
Originally Posted by djew3001
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
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP Dudes - Hi All stuart New Members & Introductions 4 05-03-04 01:22 PM
Custom PHP Scripts BdSBB Job Offers & Assistance 3 12-07-03 09:49 AM
PHP Triad/Upload form eddyvlad PHP 6 10-06-03 11:17 PM
Simple? Get result from http: in PHP wilson@cpuworks.com PHP 3 07-10-03 11:58 AM


All times are GMT -5. The time now is 04:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.