/**
  * Set ending time of the call and write log.
  *
  * @param StopwatchEvent $event
  * @param string         $resource
  */
 public function logCallDuration(StopwatchEvent $event, $resource)
 {
     if (static::IS_LOG_ACTIVE) {
         $filePath = $this->logDir . static::LOG_FILE_NAME;
         $duration = $event->getDuration() / 1000;
         $duration = number_format($duration, 3);
         $startTime = ($event->getOrigin() + $event->getStartTime()) / 1000;
         $callStart = date(static::DATE_FORMAT, (int) $startTime);
         $this->writeLog($filePath, $callStart, $resource, $duration);
     }
 }
예제 #2
0
    public function testStartTime()
    {
        $event = new StopwatchEvent(microtime(true) * 1000);
        $this->assertTrue($event->getStartTime() < 0.5);

        $event = new StopwatchEvent(microtime(true) * 1000);
        $event->start();
        $event->stop();
        $this->assertTrue($event->getStartTime() < 1);

        $event = new StopwatchEvent(microtime(true) * 1000);
        $event->start();
        usleep(100000);
        $event->stop();
        $this->assertEquals(0, $event->getStartTime(), null, self::DELTA);
    }