Skip to content

Instantly share code, notes, and snippets.

@daohoangson
Last active July 13, 2017 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daohoangson/36cc0bca9a5303d976e181af7cb705b9 to your computer and use it in GitHub Desktop.
Save daohoangson/36cc0bca9a5303d976e181af7cb705b9 to your computer and use it in GitHub Desktop.
<?php
public static function fire($event, array $args = array(), $hint = null)
{
(strpos($event, 'template') === false && (strpos($event, 'load_class') === false || $event === 'load_class') && setHeaderTimer($hint ? $hint : $event));
...
}
<?php
...
function setHeaderTimer($key)
{
static $counter = 0;
static $latestKey = null;
static $latestValue = 0;
if (!XenForo_Application::debugMode()
|| !XenForo_Application::isRegistered('fc')
|| !XenForo_Application::isRegistered('page_start_time')
) {
return;
}
$key = str_replace('XenForo_', '', $key);
$key = str_replace('_', '-', $key);
$key = preg_replace('#(.)([A-Z])#', '$1-$2', $key);
$key = preg_replace('#\-{2,}#', '-', $key);
$keyBefore = $latestKey;
$valueBefore = $latestValue;
$latestKey = sprintf('X-%02d-%s', ++$counter, $key);
$latestValue = microtime(true) - XenForo_Application::get('page_start_time');
$valueDelta = $latestValue - $valueBefore;
if ($valueDelta < .2 && $counter > 1) {
// return;
}
$fcResponse = XenForo_Application::getFc()->getResponse();
if ($keyBefore !== null) {
$fcResponse->setHeader($keyBefore, $valueBefore);
}
$fcResponse->setHeader($latestKey, sprintf('+%0.6f', $valueDelta));
$latestKey = null;
}
X-11-Xenforo-Visitor:1.0679681301117
X-12-Visitor-Setup:3.7609009742737
...
X-20-Xenforo-Datawriter-Attachmentdata:3.9337999820709
X-21-Xenforo-Datawriter-Attachment:5.5158941745758
X-22-Xenforo-Controllerpublic-Attachment:7.168967962265
X-13-Xenforo-Controllerpublic-Attachment:0.039804935455322
X-14-Xenforo-Model-Attachment:1.829607963562
X-13-Xenforo-Controllerpublic-Attachment:0.14207100868225
X-14-Xenforo-Model-Attachment:8.863872051239
...
X-20-Xenforo-Datawriter-Attachmentdata:9.442106962204
X-21-Xenforo-Datawriter-Attachment:11.492645978928
X-11-Xenforo-Visitor:0.48083186149597
X-12-Visitor-Setup:10.060799837112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment