Start and stop a timer PHP

前端 未结 8 794
北海茫月
北海茫月 2020-11-30 08:08

I need some information regarding starting and stopping a timer in PHP. I need to measure the elapsed time from the start of my .exe program (I\'m using exec()

8条回答
  •  猫巷女王i
    2020-11-30 08:47

    For your purpose, this simple class should be all you need:

    class Timer {
        private $time = null;
        public function __construct() {
            $this->time = time();
            echo 'Working - please wait..
    '; } public function __destruct() { echo '
    Job finished in '.(time()-$this->time).' seconds.'; } } $t = new Timer(); // echoes "Working, please wait.." [some operations] unset($t); // echoes "Job finished in n seconds." n = seconds elapsed

提交回复
热议问题