Пример #1
0
function ajaxShutdown()
{
    $isError = false;
    if ($error = error_get_last()) {
        switch ($error['type']) {
            case E_ERROR:
            case E_CORE_ERROR:
            case E_COMPILE_ERROR:
            case E_USER_ERROR:
            case E_PARSE:
                $log_file = ini_get("error_log");
                if (file_exists($log_file)) {
                    $number_of_characters_to_get = 5000;
                    $bf = new BigFile($log_file);
                    $text = $bf->getFromEnd($number_of_characters_to_get);
                    $lines = array_reverse(explode("\n", $text));
                    $backtrace = "";
                    foreach ($lines as $i => $line) {
                        if (strstr($line, "Fatal")) {
                            for ($j = $i; $j > 0; $j--) {
                                $backtrace .= $lines[$j] . "\n";
                            }
                            break;
                        }
                    }
                    if ($backtrace == "") {
                        $backtrace = "No Fatal error found in the last {$number_of_characters_to_get} lines of {$log_file}";
                    }
                } else {
                    $backtrace = "No error log found at " . $log_file;
                }
                $isError = true;
                break;
        }
    }
    if ($isError) {
        send_http_error(new Exception("E_ERROR " . $error['message'] . "\n file: " . $error['file'] . " (" . $error['line'] . ")", E_FATAL_ERROR), "FATAL ERROR. shutdown function tried to restore backtrace from php error log ({$log_file}):\n" . $backtrace, true);
        $response = new HttpResponse();
        $response->setStatus("400 Bad Request");
        $response->write("E_ERROR " . $error['message'] . "\n file: " . $error['file'] . " (" . $error['line'] . ")");
        $response->flush();
    }
}
Пример #2
0
 protected static function json_echo_stream(BigFile $data)
 {
     // Encode stream to base64.
     echo '"';
     $data->render();
     echo '"';
 }