当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpResponse::setStatus方法代码示例

本文整理汇总了PHP中HttpResponse::setStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::setStatus方法的具体用法?PHP HttpResponse::setStatus怎么用?PHP HttpResponse::setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse::setStatus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
}
开发者ID:rolwi,项目名称:koala,代码行数:43,代码来源:Ajax.extension.php

示例2: curl

 public static function curl($url, $httpMethod = "GET", $postFields = null, $headers = null)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
     if (ENABLE_HTTP_PROXY) {
         curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
         curl_setopt($ch, CURLOPT_PROXY, HTTP_PROXY_IP);
         curl_setopt($ch, CURLOPT_PROXYPORT, HTTP_PROXY_PORT);
         curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
     }
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_FAILONERROR, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields);
     if (self::$readTimeout) {
         curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout);
     }
     if (self::$connectTimeout) {
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
     }
     //https request
     if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     }
     if (is_array($headers) && 0 < count($headers)) {
         $httpHeaders = self::getHttpHearders($headers);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
     }
     $httpResponse = new HttpResponse();
     $httpResponse->setBody(curl_exec($ch));
     $httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE));
     if (curl_errno($ch)) {
         throw new ClientException("Speicified endpoint or uri is not valid.", "SDK.ServerUnreachable");
     }
     curl_close($ch);
     return $httpResponse;
 }
开发者ID:hyancat,项目名称:aliyun-direct-mail,代码行数:38,代码来源:HttpHelper.php

示例3: parseResponse

 /**
  *	Parses the raw HTTP response and returns a response object
  **/
 protected function parseResponse($output, $ch = null)
 {
     $response = new HttpResponse();
     if ($output) {
         $lines = explode("\n", $output);
         $isHeader = true;
         $buffer = array();
         foreach ($lines as $line) {
             if ($isHeader) {
                 if (preg_match('/^\\s*$/', $line)) {
                     // Header/body separator
                     $isHeader = false;
                 } else {
                     // This is a real HTTP header
                     if (preg_match('/^([^:]+)\\:(.*)$/', $line, $matches)) {
                         //echo "HEADER: [", $matches[1], ']: [', $matches[2], "]\n";
                         $name = trim($matches[1]);
                         $value = trim($matches[2]);
                         $response->addHeader($name, $value);
                     } else {
                         // This is the status response
                         //echo "HEADER: ", trim($line), "\n";
                         if (preg_match('/^(HTTP\\/\\d\\.\\d) (\\d*) (.*)$/', trim($line), $matches)) {
                             $response->setStatus($matches[2]);
                             $response->setStatusMsg($matches[3]);
                             $response->setVersion($matches[1]);
                         }
                     }
                 }
             } else {
                 $buffer[] = $line;
             }
         }
         // The buffer is the HTTP Entity Body
         $response->setBody(implode("\n", $buffer));
     } else {
         $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         if ($statusCode == 0) {
             $response->setStatus(502);
             $response->setStatusMsg('CURL Error');
         } else {
             $response->setStatus($statusCode);
             $response->setStatusMsg('CURL Response');
         }
     }
     return $response;
 }
开发者ID:plescanicolai,项目名称:osCommerce,代码行数:50,代码来源:HttpClient.php

示例4: 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;
     }
 }
开发者ID:rolwi,项目名称:koala,代码行数:77,代码来源:FrontController.class.php

示例5: reject

 /**
  * Rejects the request.
  *
  * @param string $message
  * @param int $httpResponseCode
  */
 public function reject($message = "Rejected", $httpResponseCode = 400)
 {
     $this->httpResponse->setStatus($httpResponseCode . ' ' . $message);
 }
开发者ID:stegru,项目名称:php-websockets,代码行数:10,代码来源:WebSocketRequest.php

示例6: 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();
}
开发者ID:arnereichenberg,项目名称:toernon-api,代码行数:26,代码来源:api.php


注:本文中的HttpResponse::setStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。