Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $config = $this->diContainer->get(CCS::CONFIG);
- $logger = $this->diContainer->get(CCS::LOGGER);
- $registry = $this->diContainer->get(CCS::REGISTRY);
- $utils = $this->diContainer->get(CCS::UTILS);
- ini_set('display_errors', boolval(0 !== $registry->devmode));
- error_reporting(E_ALL);
- set_error_handler(
- function ($exception) use ($logger) {
- if ($exception instanceof \Exception) {
- $logger->error($exception->__toString());
- } else {
- $logger->error(
- json_encode(debug_backtrace()) . json_encode($exception)
- );
- }
- }
- );
- set_exception_handler(
- function () use ($logger) {
- $logger->error(json_encode(debug_backtrace()));
- }
- );
- register_shutdown_function(
- function () use ($logger, $registry, $utils) {
- $memory_difference = (
- memory_get_usage() - $registry->metricsMemory
- );
- $executionDifference = (
- microtime(true) - $registry->metricsMxecution
- );
- if (0 !== $registry->devmode) {
- $logger->info(
- sprintf(
- 'Shutdown completed [%s] - [%s]',
- $utils->timeToHuman($executionDifference),
- $utils->bytesToHuman($memoryDifference)
- )
- );
- }
- }
- );
- $timezone = $config->get('app_timezone', 'US/Eastern');
- date_default_timezone_set($timezone);
- public function timeToHuman($microseconds, $precision = 3)
- {
- $units = ['μs', 'ns', 'ms', 's'];
- $micro = max($microseconds, 0);
- $pow = 0;
- if (1000 < $micro) {
- $pow = floor(($micro ? log($micro) : 0) / log(1000));
- $pow = min($pow, count($units) - 1);
- $micro /= (1 << (10 * $pow));
- }
- return round($micro, $precision) . ' ' . $units[$pow];
- }
- public function bytesToHuman($bytes, $precision = 2)
- {
- $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- $bytes = max($bytes, 0);
- $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
- $pow = min($pow, count($units) - 1);
- $bytes /= (1 << (10 * $pow));
- return round($bytes, $precision) . ' ' . $units[$pow];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement