Jump to content

Create a clock in PHP


mlnsharma

Recommended Posts

[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?

Link to comment
https://forums.phpfreaks.com/topic/172237-create-a-clock-in-php/
Share on other sites

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();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.