Records the debugger stop and stystem stop time
Ideally the last method to be called before the output is sent to the server

@return void
16754
public static function stop()
    {

        //Get usage data
        $now = microtime(true);
        $speed = number_format(1000 * ($now - static::$time), 2);
        $_memory = memory_get_usage();
        $units = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB');
        $memory = @round($_memory / pow(1024, ($i = floor(log($_memory, 1024)))), 2) . ' ' . $units[$i];
        $queries = '0';
        //Get Query usage
        //@TODO this smells, a method to detect that the database has been installed;
        $installed = (bool)\Library\Config::getParam("installed", FALSE, "database");

        if ($installed):

            $database = \Library\Database::getInstance();
            $queries = $database->getTotalQueryCount();

        endif;

        //Log usage
        self::log($now, _t("Stop execution time"), "info");

        $output = \Library\Output::getInstance();
        $showMessage = \Library\Config::getParam("mode", 1, "environment");
        if ((int)$showMessage < 2) {
            $output = \Library\Output::getInstance();
            $output->set("debug", array("displaylog" => true));
            $output->set("debug", array("queries" => $queries));
            $output->set("debug", array("log" => static::$log));
        }
        //Set the debugger output
        $output->set("debug", array("start" => static::$time));
        $output->set("debug", array("stop" => $now));
        $output->set("debug", array("speed" => $speed));
        $output->set("debug", array("memory" => $memory));

        //Library\Date::difference($now, $speed);
        //print_R(static::getInstance());


    }
686650
public function onShutdown()
    {
        // Get the last error if there was one, if not, let's get out of here.
        if (!$error = error_get_last()) {
            return;
        }

        $fatal  = array(E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR,E_USER_ERROR,E_RECOVERABLE_ERROR);
        if (!in_array($error['type'], $fatal)) {
            return;
        }

        $message   = '[Shutdown Error]: %s';
        $message   = sprintf($message, $error['message']);
        $backtrace = array(array('file' => $error['file'], 'line' => $error['line']));

        $this->client->notifyOnError($message, $backtrace, 'error');
        error_log($message.' in: '.$error['file'].':'.$error['line']);
    }
713089
public function onShutdown()
    {
        try {
            $e = error_get_last();
            if (in_array($e['type'], [
                E_ERROR,
                E_PARSE,
                E_CORE_ERROR,
                E_COMPILE_ERROR,
                E_USER_ERROR,
                E_RECOVERABLE_ERROR
            ]))
            {
                Log::error($e['message'], [
                    'trace' => [],
                    'errorFile'  =>  $e['file'],
                    'errorLine'  =>  $e['line'],
                ]);
            }
            $logger = App::getBean('Logger');
            $logger->save();
        } catch(\Throwable $th) {
            echo $th->getMessage(), ' ', $th->getFile(), ':', $th->getLine(), PHP_EOL;
        }
    }
971133
public function stop(int $duration = null)
    {
        // Stop the Timer
        $this->timer->stop();

        // Store Summary
        $this->summary['duration']  = $duration ?? round($this->timer->getDurationInMilliseconds(), 3);
        $this->summary['headers']   = (function_exists('xdebug_get_headers') === true) ? xdebug_get_headers() : [];
        $this->summary['backtrace'] = debug_backtrace($this->backtraceLimit);
    }
1007532
public static function shutdown()
    {
        if (defined('QCUBED_TIMER_OUT_FILE') && class_exists('\\QCubed\\Timer')) {
            $strTimerOutput = \QCubed\Timer::VarDump(false);
            if ($strTimerOutput) {
                file_put_contents(QCUBED_TIMER_OUT_FILE, $strTimerOutput . "\n", FILE_APPEND);
            }
        }

        $error = error_get_last();
        if ($error &&
            is_array($error)
            /*&&
            (!defined('QCodeGen::DebugMode') || QCodeGen::DebugMode)*/
        ) { // if we are codegenning, only error if we are in debug mode. Prevents chmod error.

            self::handleError (
                $error['type'],
                $error['message'],
                $error['file'],
                $error['line']
            );
        }
    }
311225
protected function save_stack_trace()
    {
        if ($this->debug) {
            $file = fopen($this->stack_trace_file, 'w');
            if (!$file) {
                $this->error = 605;
            } else {
                fwrite($file, print_r($this->stack_trace, true));
                fclose($file);
            }
        }
    }
1142470
public static function record_start() {
        self::$before = microtime(true);
        self::$lastsavepoint = self::$before;
        self::$isrecording = true;
    }
926478
public function releaseTimedout()
    {
        $trx = models\DbMessage::getDb()->transaction !== null ? null : models\DbMessage::getDb()->beginTransaction();
        $primaryKey = models\DbMessage::primaryKey();
        $message_ids = models\DbMessage::find()
            ->withQueue($this->id)
            ->timedout($this->timeout)
            ->select($primaryKey)
            ->asArray()
            ->all();
        models\DbMessage::updateAll(['status' => Message::AVAILABLE], ['in', $primaryKey, $message_ids]);
        if ($trx !== null) {
            $trx->commit();
        }

        return $message_ids;
    }
1336250
function debug($str, $TYPE = 0, $file = "", $line = 0)
    {
        if ($this->debug)
        {
            echo "<br>[$file:$line:" . ($this->getDiffTime()) . "]$str";
            flush();
            if ($TYPE == 1)
            {
                exit;
            }
        }
    }
526827
public function _shutdown()
	{
		if ($this->_registered && $error = error_get_last())
		{
			try
			{
				// clear the output buffer if we can
				if(ob_get_level()>=1) ob_end_clean();

				// build an error exception
				if (isset($error['type']) && in_array($error['type'],
					array(E_ERROR, E_PARSE, E_COMPILE_ERROR)))
				{
					$this->_handleError(
						$error['type'],
						$error['message'],
						$error['file'],
						$error['line']
						);
				}
			}
			catch(Exception $e)
			{
			}
		}
	}
279951
public function shutdown()
    {
        $exceptions = $this->client_holder->shutdown();

        if ($this->hasLogger()) {
            foreach ($exceptions as $exception) {
                printf(
                    "Exception caught during shutdown: %s\n",
                    (string) $exception
                );
            }

            $this->logger = null;
        }

        $this->client_poolers = [];
        $this->connection->close();
        $this->is_shutdown = true;
    }
1016148
public function debug() {
        echo "filePath    = " . $this->filePath . PHP_EOL;
        echo "startMarker = " . $this->startMarker . PHP_EOL;
        echo "endMarker   = " . $this->endMarker . PHP_EOL;
        echo "startIndex  = " . $this->startIndex . PHP_EOL;
        echo "endIndex    = " . $this->endIndex . PHP_EOL;
        echo "numLines    = " . $this->numLines . PHP_EOL;
        echo "Start       = " . print_r($this->beforeLines, true);
        echo "Auto      = " . print_r($this->autoLines, true);
        echo "End         = " . print_r($this->afterLines, true);
        return $this;
    }
675680
public static function finish() {

        if(empty(self::$profiler) === false) {

            self::$profiler = array_merge([
                'elapsed'   =>  self::getTime(time() - self::$profiler['start']),
                'memory'    =>  self::getMemoryUsage(),
                'cpu'       =>  self::getUsageCPU(),
                'stack'     =>  self::getStackCalls()
            ], self::$profiler);

            unset(self::$profiler['start']);
        }
    }
750420
public function debug(): void
    {
        foreach ($this->formatters as $locale => $formats) {
            echo "\n# $locale\n";
            foreach ($formats as $name => $format) {
                echo "## $name\n";
                echo "Locale: " . $format->getLocale(\Locale::VALID_LOCALE) . "\n" .
                     "DateType: " . $format->getDateType() . "\n" .
                     "TimeType: " . $format->getTimeType() . "\n" .
                     "Calendar: " . $format->getCalendar() . "\n" .
                     "Pattern: " . $format->getPattern() . "\n\n";
            }
        }
    }
910665
private function finish()
    {
        if ($this->main_database !== null) {
            $this->main_database->disconnect();
        }

        $this->microtime_end = microtime(true);
        $this->microtime_elapsed = $this->microtime_end - $this->microtime_start;
        $this->traceLog("Execution time", sprintf("%.3f ms", $this->microtime_elapsed * 1000));
    }
531895
public function debugClose() {

		$sConfig = get_called_class();

		unset(static::$_lPoolDataChange[$sConfig][$this->_mID]);
		unset(static::$_lPoolData[$sConfig][$this->_mID]);
	}
265208
public function PHPShutdownHandler()
    {
        session_write_close();
        if ($lasterror = error_get_last()) {
            $message = $lasterror['message'] . ' | File: {file} | Ln: {line}';
            $context = array(
                'file' => $lasterror['file'],
                'line' => $lasterror['line']
            );
            $this->logger->log($this->shutdownLogLevel, $message, $context);
        }
    }