Start and stop a timer PHP

前端 未结 8 795
北海茫月
北海茫月 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:59

    You can use Timer Class

        start();
       }
    
       # Start counting time
       function start() {
          $this->start = $this->_gettime();
       }
    
       # Stop counting time
       function stop() {
          $this->stop    = $this->_gettime();
          $this->elapsed = $this->_compute();
       }
    
       # Get Elapsed Time
       function elapsed() {
          if ( !$elapsed )
             $this->stop();
    
          return $this->elapsed;
       }
    
       # Resets Timer so it can be used again
       function reset() {
          $this->start   = 0;
          $this->stop    = 0;
          $this->elapsed = 0;
       }
    
       #### PRIVATE METHODS ####
    
       # Get Current Time
       function _gettime() {
          $mtime = microtime();
          $mtime = explode( " ", $mtime );
          return $mtime[1] + $mtime[0];
       }
    
       # Compute elapsed time
       function _compute() {
          return $this->stop - $this->start;
       }
    }
    
    ?>
    

提交回复
热议问题