Exemplo n.º 1
0
        $line = $error['line'];
        $log = "{$message} ({$file}:{$line})\nStack trace:\n";
        $trace = debug_backtrace();
        foreach ($trace as $i => $t) {
            if (!isset($t['file'])) {
                $t['file'] = 'unknown';
            }
            if (!isset($t['line'])) {
                $t['line'] = 0;
            }
            if (!isset($t['function'])) {
                $t['function'] = 'unknown';
            }
            $log .= "#{$i} {$t['file']}({$t['line']}): ";
            if (isset($t['object']) && is_object($t['object'])) {
                $log .= get_class($t['object']) . '->';
            }
            $log .= "{$t['function']}()\n";
        }
        if (isset($_SERVER['REQUEST_URI'])) {
            $log .= '[QUERY] ' . $_SERVER['REQUEST_URI'];
        }
        error_log($log);
        $this->response($this->currentFd, $log);
    }
}
$server = new HttpServer();
$server->onRequest(function ($server) {
    $server->response("<h1>hello world</h1>");
});
$server->run();