HI, I've got a script which shows elapsed time since a news ticker was last modified by a pseudo-cron job script but I would like the output to update once a second as a real-time clock ...

I've looked at lots of php and java scripts but have been completely unsuccessful in getting the output to refresh every second.

Perhaps one of you experienced coders could help. Here's the code I have at the moment ...

<?php

function calcElapsedTime($time)

{

   $diff = time()-$time;
   $hrsDiff = floor($diff/60/60);
   $diff -= $hrsDiff*60*60;
   $minsDiff = floor($diff/60);
   $diff -= $minsDiff*60;
   $secsDiff = $diff;

// Hours

if ($hrsDiff < 10)
{
echo "&nbsp;0$hrsDiff&nbsp;:";
}
elseif ($hrsDiff > 9)
{
echo "&nbsp;$hrsDiff&nbsp;:";
}

// Minutes

if ($minsDiff < 10)
{
echo "&nbsp;0$minsDiff&nbsp;:";
}
elseif ($minsDiff > 9)
{
echo "&nbsp;$minsDiff&nbsp;:";
}

// Seconds

if ($secsDiff < 10)
{
echo "&nbsp;0$secsDiff";
}
elseif ($secsDiff > 9)
{
echo "&nbsp;$secsDiff";
}

}

calcElapsedTime(filemtime('ticker.htm'));

?>

Any ideas on how to add a "setTimeout()" type of loop to refresh the output once a second would be greatfully recieved ...

Thank you in advance.

    sleep(1); <- stops the action for one second

    You could write something a little more involved with it so it would be more like setTimeout but I don't think it's necessary.

      Write a Reply...