/** * @param MeasurableInterface $site * @param int $precision * * @return float|string */ public function site_loading_time(MeasurableInterface $site, $precision = 3) { if ($site->isStatusFailed()) { return 'Sorry, can\'t test this one, test failed'; } return round($site->getLoadingTime(), $precision) . ' ms'; }
/** * @param MeasurableInterface $measurable * * @return MeasurableInterface */ public function measureLoadTime(MeasurableInterface $measurable) { $t1 = microtime(true); $results = @file_get_contents($measurable->getUrl()); $t2 = microtime(true); $time = ($t2 - $t1) * 1000; if (is_string($results)) { $measurable->setLoadingTime($time); $measurable->setStatusSuccess(); } else { $measurable->setStatusFailed(); } return $measurable; }
/** * Generate log string from single $site * @param MeasurableInterface $site * * @return string */ public function getLogLine(MeasurableInterface $site) { if ($site->isStatusSuccess()) { return sprintf("%s - Benchmarking site: %s - it took %d ms to load the site\n", date('Y-m-d H:i:s'), $site->getUrl(), $site->getLoadingTime()); } else { return sprintf("%s - Benchmarking site: %s - benchmark failed\n", date('Y-m-d H:i:s'), $site->getUrl()); } }