<?php
class Statistic_Timing {
// called from _layout.phtml save page timings to iStat
/*
Hourly Statistic gathered
hit - number of ALL hits
hit_visitor - no bots - user-agent detection only
hit_google - google hits
hit_obot - other bots hits
time - time to generate page
Number of pages hits where:
hit_02 (0-0.2 seconds), hit_05 (0.2-0.5 seconds), hit_1 (0.5-1 seconds), hit_1p (1+seconds)
Excess timing (time over 2 seconds)
time_2p
Worst performing url (& time):
data => [time, [uri => uri]]
Above statistic divided into 3(4) Nodes:
page_timing_pfl - PFL
page_timing_profile - PROFILE
page_timing_profile - OTHER
page_timing_facet - OTHER
page_timing_debug - all non-production server statistic
*/
static function iStatPageTiming() {
$time = microtime(1) - $_SERVER['REQUEST_TIME_FLOAT'];
$ua = $_SERVER['HTTP_USER_AGENT']??'';
$google = preg_match('/googlebot/i', $ua);
$bot = preg_match('/bot|crawl|slurp|spider/i', $ua);
$uri = $_SERVER['REQUEST_URI'];
$apcHitList = "hit_02 hit_05 hit_1 hit_1p time_1p hit_google hit_obot hit_visitor hit_real_visitor hit-browser_dom_ready time-browser_dom_ready hit-browser_page_load time-browser_page_load hit-browser";
$ts = ["time" => $time];
if ("radaris.com" == C(".radaris")) { //
switch (\RDSite::siteID()) {
case \RDSite::SITE_ID_HOMEMETRY:
case \RDSite::SITE_ID_REHOLD:
$node = "page_timing_address";
break;
case \RDSite::SITE_ID_PHONEOWNER_COM:
case \RDSite::SITE_ID_PHONEOWNER_US:
case \RDSite::SITE_ID_PHONEID_US:
$node = "page_timing_phone";
break;
case \RDSite::SITE_ID_TRUSTORIA:
if (CD("prof_cat_id")) {
$node = "page_timing_profcat";
foreach (Prof_Helper::categoriesWithDomains() as $pcid => $pcinfo) {
$apcHitList .= " hit_c$pcid";
}
$ts["hit_c" . CD("prof_cat_id")] = 1;
} else {
$node = "page_timing_prof";
}
break;
case \RDSite::SITE_ID_RADARIS:
if (starts_with($uri, "/f/")) {
$node = "page_timing_facet";
} elseif (starts_with($uri, "/p/")) {
$node = "page_timing_pfl";
} elseif (starts_with($uri, "/~")) {
$node = "page_timing_profile";
} else {
$node = "page_timing_radaris";
}
break;
default:
$node = "page_timing_other";
break;
}
} else {
$node = "page_timing_debug";
}
$t = "1p";
if ($time < 0.2)
$t = "02";
elseif ($time < 0.5)
$t = "05";
elseif ($time < 1)
$t = "1";
$t = "hit_$t";
$ts[$t] = 1;
if ($time > 1)
$ts['time_1p'] = $time - 1;
if ($google)
$ts['hit_google'] = 1;
if ($bot && !$google)
$ts['hit_obot'] = 1;
if (!$bot)
$ts['hit_visitor'] = 1;
$slow_url = [];
if ($time > 2)
i('Stat', $node)->trackMax('time', $time, ['uri' => $uri]);
if (once("slow-page-time:$node", 300)) { // once every 5 minute
$slow_url = i('Stat', $node)->trackMax('time');
if (!$slow_url[0])
$slow_url = [];
else
\Log::text(round($slow_url[0], 1) . " " . $slow_url[1]['uri'], "slow-pages");
}
# \Log::text("apcHit($node): ".x2s($ts). " ".x2s($slow_url));
// hit_real_visitor is added by /srv/a.uping
}
}