He's trying to partially recreate what the SDK notifications/activities modules do with the elapsed time.
e.g.
(0 min)
I have a better idea of how to do it in traditional languages rather than PHP, but the general algorithm in the loop should probably be along the lines of:
1) access the current time and store it as the start time,
2) when the action is done access the current time again and subtract the start time from it,
3) before printing, you may have to manipulate the value with multipliers to output in the unit you're looking for.
To take the next step by making it comprehensive with things like
(2 hrs, 3 mins)
(which is the best way)
you'll want to check if the value in seconds is divisible by 60, and if so, reset seconds to 0 and increment minutes by 1. Likewise for minutes-into-hours. But depends on what you want to show.