mlnsharma Posted August 28, 2009 Share Posted August 28, 2009 [1] In Javascript, there is a function setTimeout() to call a function with a time interval.. In PHP, is there any similar in-built function ? If there is a different solution, kindly provide me the code in php.. [2] Using sleep(): I tried to create a page with sleep(). <? echo "hello"; sleep(5) echo "world"; ?> I did not get a "hello and after 5 seconds world". Instead it took 5 seconds to load and displayed entire content at once. Can any provide me solution to these two problems? Quote Link to comment https://forums.phpfreaks.com/topic/172237-create-a-clock-in-php/ Share on other sites More sharing options...
kirisutegomen Posted August 28, 2009 Share Posted August 28, 2009 i think you have to use javascript to do that but i dont know how Quote Link to comment https://forums.phpfreaks.com/topic/172237-create-a-clock-in-php/#findComment-908137 Share on other sites More sharing options...
oni-kun Posted August 28, 2009 Share Posted August 28, 2009 There is no settimeout in php, you could use the output buffer to display 'hello' before the sleep() cycle is finished, but it's buggy and is not a good solution. I had another example for another thread on this topic.. but try this code.. place it at the top of your page, ob_start() has to atleast. <?php if (ob_get_level() == 0) ob_start(); echo "Hello"; echo str_pad('',4096)."\n"; ob_flush(); flush(); sleep(5); echo "world"; echo str_pad('',4096)."\n"; ob_flush(); flush(); sleep(0); ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172237-create-a-clock-in-php/#findComment-908142 Share on other sites More sharing options...
mlnsharma Posted August 28, 2009 Author Share Posted August 28, 2009 Thank you.. It is solved and i believe that with PHP, there is no function like "setTimeout" for a timer.. Quote Link to comment https://forums.phpfreaks.com/topic/172237-create-a-clock-in-php/#findComment-908194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.