If you want to calculate the time particular PHP script has been running you do it as following:
//Remember beginning time of the script
define("START_TIME", time());
//Do some loop or whatever
...
//At the end, calculate the difference of start and current time
echo "This script has been running for ".(time() - START_TIME)."\n";
Well, this is all nice, but imagine you're making a class/library, that might be included later in the script and that needs to calculate the runtime too.
Is there a function in PHP that would give me the timestamp when the script was launched - or a function that would allow me to deduct that?
This is what I need:
class Blah {
public getRuntime() {
static $startTime = get_start_time_magic_function();
return time() - $startTime;
}
}
My reason to require is, that I have a "infinite" loop in a class, that should automatically end when execution limit is going to take effect. If the script was killed by PHP, that would cause harm to processed data.