本文整理汇总了PHP中HttpResponse::flush方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::flush方法的具体用法?PHP HttpResponse::flush怎么用?PHP HttpResponse::flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajaxShutdown
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: handleRequest
public function handleRequest(AjaxRequestObject $ajaxRequestObject, AjaxResponseObject $ajaxResponseObject)
{
$response = new HttpResponse();
$extension = ExtensionMaster::getInstance()->getExtensionForNamespace($ajaxRequestObject->getNamespace());
if (isset($extension)) {
if ($extension instanceof ICommandAdapter) {
if ($ajaxRequestObject->getCommand() != "") {
if ($ajaxRequestObject->getCommand() == "databinding") {
$command = new Databinding();
} else {
if ($extension->isValidCommand($ajaxRequestObject->getCommand())) {
$command = $extension->getCommand($ajaxRequestObject->getCommand());
}
}
if ($command instanceof IAjaxCommand && $command->validateData($ajaxRequestObject)) {
try {
$command->processData($ajaxRequestObject);
$ajaxResponseObject = $command->ajaxResponse($ajaxResponseObject);
} catch (Exception $e) {
$response->setStatus("400 Bad Request");
$response->write("Command processing error: \"{$e->getMessage()}\"");
$response->flush();
if (DEVELOPMENT_MODE) {
throw $e;
}
exit;
}
if ($ajaxResponseObject instanceof AjaxResponseObject) {
$data = \Widgets\Widget::getData($ajaxResponseObject->getWidgets());
$stat = "";
if ($_SESSION["STATISTICS_LEVEL"] > 0) {
$stat = "console.log('Serveranfragen: " . $GLOBALS["STEAM"]->get_request_count() . " / " . $GLOBALS["STEAM"]->get_globalrequest_count() . "');";
}
if ($_SESSION["STATISTICS_LEVEL"] > 1 && isset($GLOBALS["page_time_start"])) {
$requestMap = $GLOBALS["STEAM"]->get_globalrequest_map();
$requestTime = $GLOBALS["STEAM"]->get_globalrequest_time();
$requestString = "";
foreach ($requestMap as $method => $count) {
$requestString .= "console.log('Methode {$method} -> {$count} mal in " . round($requestTime[$method] * 1000) . " ms');";
}
$stat .= "console.log('Zeit: " . round((microtime(TRUE) - $GLOBALS["page_time_start"]) * 1000) . " ms');" . $requestString;
}
header("Content-type: text/plain");
$response->write(json_encode(array("status" => $ajaxResponseObject->getStatus(), "html" => $data["html"], "data" => $ajaxResponseObject->getData(), "css" => $data["css"], "js" => $data["js"] . $stat, "postjs" => $data["postjs"])));
$response->flush();
exit;
} else {
$response->setStatus("400 Bad Request");
$response->write("Wrong response type for \"{$ajaxRequestObject->getCommand()}\"");
$response->flush();
exit;
}
} else {
$response->setStatus("400 Bad Request");
$response->write("Command \"{$ajaxRequestObject->getCommand()}\" not valid.");
$response->flush();
exit;
}
} else {
$response->setStatus("400 Bad Request");
$response->write("Command parameter missing.");
$response->flush();
exit;
}
} else {
$response->setStatus("400 Bad Request");
$response->write("Extension doesn't support commands.");
$response->flush();
exit;
}
} else {
$response->setStatus("400 Bad Request");
$response->write("Not extension found for url");
$response->flush();
exit;
}
}
示例3: HttpResponse
<?php
require_once "errors.php";
require_once "Exceptions.php";
require_once "db.php";
require_once 'HttpRequest.php';
require_once 'HttpResponse.php';
require_once 'Authenticator.php';
require_once 'Router.php';
require_once 'Trips.php';
$resp = new HttpResponse();
try {
$db = new mysqli($dbhost, $dbuser, $dbpw, $dbdb);
$req = new HttpRequest();
$auth = new Authenticator($db, $req);
//the router handles all of the other stuff (loading controller etc.)
$router = new Router($req, $resp, $db, $auth);
$content = $router->executeRoute();
$resp->write($content);
$resp->flush();
} catch (Exception $e) {
$resp->setStatus(400);
$resp->addHeader('error', $e->getMessage());
$resp->write('{"exception" : "' . $e->getMessage() . ' [' . $e->getFile() . '#' . $e->getLine() . ']"}');
$resp->flush();
}