X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp%2FPage.php;h=63314561191a672b9ed8aced03a99bb3382e62b5;hb=4deee0932c0b6a0d6443438c29dfc5f7781dda79;hp=1b499f614c064b9373579b6c11399f7c3af3a968;hpb=7cd85873ee321263ff9b4e77fc121dca1c9dae6f;p=friendica.git diff --git a/src/App/Page.php b/src/App/Page.php index 1b499f614c..6331456119 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -1,6 +1,6 @@ timestamp = microtime(true); $this->basePath = $basepath; } + public function setLogging(string $method, string $module, string $command) + { + $this->method = $method; + $this->module = $module; + $this->command = $command; + } + + public function logRuntime(IManageConfigValues $config, string $origin = '') + { + $ignore = $config->get('system', 'runtime_ignore'); + if (in_array($this->module, $ignore) || in_array($this->command, $ignore)) { + return; + } + + $signature = !empty($_SERVER['HTTP_SIGNATURE']); + $load = number_format(System::currentLoad(), 2); + $runtime = number_format(microtime(true) - $this->timestamp, 3); + if ($runtime > $config->get('system', 'runtime_loglimit')) { + Logger::debug('Runtime', ['method' => $this->method, 'module' => $this->module, 'runtime' => $runtime, 'load' => $load, 'origin' => $origin, 'signature' => $signature, 'request' => $_SERVER['REQUEST_URI'] ?? '']); + } + } + /** * Whether a offset exists * @@ -169,7 +200,7 @@ class Page implements ArrayAccess * @param string $media * @see Page::initHead() */ - public function registerStylesheet($path, string $media = 'screen') + public function registerStylesheet(string $path, string $media = 'screen') { $path = Network::appendQueryParam($path, ['v' => FRIENDICA_VERSION]); @@ -229,7 +260,7 @@ class Page implements ArrayAccess $shortcut_icon = $config->get('system', 'shortcut_icon'); if ($shortcut_icon == '') { - $shortcut_icon = 'images/friendica-32.png'; + $shortcut_icon = 'images/friendica.svg'; } $touch_icon = $config->get('system', 'touch_icon'); @@ -262,7 +293,7 @@ class Page implements ArrayAccess * * Taken from http://webcheatsheet.com/php/get_current_page_url.php */ - private function curPageURL() + private function curPageURL(): string { $pageURL = 'http'; if (!empty($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) { @@ -378,10 +409,19 @@ class Page implements ArrayAccess */ public function exit(ResponseInterface $response) { + header(sprintf("HTTP/%s %s %s", + $response->getProtocolVersion(), + $response->getStatusCode(), + $response->getReasonPhrase()) + ); + foreach ($response->getHeaders() as $key => $header) { if (is_array($header)) { $header_str = implode(',', $header); + } else { + $header_str = $header; } + if (empty($key)) { header($header_str); } else { @@ -410,6 +450,9 @@ class Page implements ArrayAccess { $moduleName = $args->getModuleName(); + $this->command = $moduleName; + $this->method = $args->getMethod(); + /* Create the page content. * Calls all hooks which are including content operations * @@ -417,7 +460,6 @@ class Page implements ArrayAccess */ $timestamp = microtime(true); $this->initContent($response, $mode); - $profiler->set(microtime(true) - $timestamp, 'content'); // Load current theme info after module has been initialized as theme could have been set in module $currentTheme = $app->getCurrentTheme(); @@ -445,6 +487,8 @@ class Page implements ArrayAccess */ $this->initFooter($app, $mode, $l10n); + $profiler->set(microtime(true) - $timestamp, 'aftermath'); + if (!$mode->isAjax()) { Hook::callAll('page_end', $this->page['content']); } @@ -456,10 +500,16 @@ class Page implements ArrayAccess } foreach ($response->getHeaders() as $key => $header) { + if (is_array($header)) { + $header_str = implode(',', $header); + } else { + $header_str = $header; + } + if (empty($key)) { - header($header); + header($header_str); } else { - header("$key: $header"); + header("$key: $header_str"); } } @@ -487,11 +537,7 @@ class Page implements ArrayAccess } if ($_GET["mode"] == "raw") { - header("Content-type: text/html; charset=utf-8"); - - echo substr($target->saveHTML(), 6, -8); - - exit(); + System::httpExit(substr($target->saveHTML(), 6, -8), Response::TYPE_HTML); } }