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


PHP HTTP::HTTPTranslate方法代码示例

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


在下文中一共展示了HTTP::HTTPTranslate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Wait

 public function Wait($timeout = false, $readfps = array(), $writefps = array(), $exceptfps = NULL)
 {
     $readfps["ws_s"] = $this->fp;
     if ($timeout === false || $timeout > $this->defaultkeepalive) {
         $timeout = $this->defaultkeepalive;
     }
     foreach ($this->clients as $id => &$client) {
         if ($client["writedata"] === "") {
             $readfps["ws_c_" . $id] = $client["fp"];
         }
         if ($client["writedata"] !== "" || $client["websocket"] !== false && $client["websocket"]->NeedsWrite()) {
             $writefps["ws_c_" . $id] = $client["fp"];
         }
         if ($client["websocket"] !== false) {
             $timeout2 = $client["websocket"]->GetKeepAliveTimeout();
             if ($timeout > $timeout2) {
                 $timeout = $timeout2;
             }
         }
     }
     $result = array("success" => true, "clients" => array(), "removed" => array(), "readfps" => array(), "writefps" => array(), "exceptfps" => array());
     $result2 = @stream_select($readfps, $writefps, $exceptfps, $timeout);
     if ($result2 === false) {
         return array("success" => false, "error" => HTTP::HTTPTranslate("Wait() failed due to stream_select() failure.  Most likely cause:  Connection failure."), "errorcode" => "stream_select_failed");
     }
     // Handle new connections.
     if (isset($readfps["ws_s"])) {
         while (($fp = @stream_socket_accept($this->fp, 0)) !== false) {
             // Enable non-blocking mode.
             stream_set_blocking($fp, 0);
             $this->clients[$this->nextclientid] = array("id" => $this->nextclientid, "readdata" => "", "writedata" => "", "request" => false, "path" => "", "url" => "", "headers" => array(), "lastheader" => "", "websocket" => false, "fp" => $fp);
             $this->nextclientid++;
         }
         unset($readfps["s"]);
     }
     // Handle clients in the read queue.
     foreach ($readfps as $cid => $fp) {
         if (!is_string($cid) || strlen($cid) < 6 || substr($cid, 0, 5) !== "ws_c_") {
             continue;
         }
         $id = (int) substr($cid, 5);
         if (!isset($this->clients[$id])) {
             continue;
         }
         if ($this->clients[$id]["websocket"] !== false) {
             $this->ProcessClientQueuesAndTimeoutState($result, $id, true, isset($writefps[$cid]));
             // Remove active WebSocket clients from the write queue.
             unset($writefps[$cid]);
         } else {
             $result2 = @fread($fp, 8192);
             if ($result2 === false || feof($fp)) {
                 @fclose($fp);
                 unset($this->clients[$id]);
             } else {
                 $this->clients[$id]["readdata"] .= $result2;
                 if (strlen($this->clients[$id]["readdata"]) > 100000) {
                     // Bad header size.  Just kill the connection.
                     @fclose($fp);
                     unset($this->clients[$id]);
                 } else {
                     while (($pos = strpos($this->clients[$id]["readdata"], "\n")) !== false) {
                         // Retrieve the next line of input.
                         $line = rtrim(substr($this->clients[$id]["readdata"], 0, $pos));
                         $this->clients[$id]["readdata"] = (string) substr($this->clients[$id]["readdata"], $pos + 1);
                         if ($this->clients[$id]["request"] === false) {
                             $this->clients[$id]["request"] = trim($line);
                         } else {
                             if ($line !== "") {
                                 // Process the header.
                                 if ($this->clients[$id]["lastheader"] != "" && (substr($line, 0, 1) == " " || substr($line, 0, 1) == "\t")) {
                                     $this->clients[$id]["headers"][$this->clients[$id]["lastheader"]] .= $header;
                                 } else {
                                     $pos = strpos($line, ":");
                                     if ($pos === false) {
                                         $pos = strlen($line);
                                     }
                                     $this->clients[$id]["lastheader"] = HTTP::HeaderNameCleanup(substr($line, 0, $pos));
                                     $this->clients[$id]["headers"][$this->clients[$id]["lastheader"]] = ltrim(substr($line, $pos + 1));
                                 }
                             } else {
                                 // Headers have all been received.  Process the client request.
                                 $request = $this->clients[$id]["request"];
                                 $pos = strpos($request, " ");
                                 if ($pos === false) {
                                     $pos = strlen($request);
                                 }
                                 $method = (string) substr($request, 0, $pos);
                                 $request = trim(substr($request, $pos));
                                 $pos = strrpos($request, " ");
                                 if ($pos === false) {
                                     $pos = strlen($request);
                                 }
                                 $path = (string) substr($request, 0, $pos);
                                 if ($path === "") {
                                     $path = "/";
                                 }
                                 $this->clients[$id]["path"] = $path;
                                 $this->clients[$id]["url"] = "ws://" . $client["headers"]["Host"] . $path;
                                 // Let a derived class handle the new connection (e.g. processing Origin and Host).
                                 // Since the 'websocketclass' is instantiated AFTER this function, it is possible to switch classes on the fly.
//.........这里部分代码省略.........
开发者ID:watsonweber,项目名称:ultimate-web-scraper,代码行数:101,代码来源:websocket_server.php

示例2: ProcessReadData

 protected function ProcessReadData()
 {
     while (($frame = $this->ReadFrame()) !== false) {
         // Verify that the opcode is probably valid.
         if ($frame["opcode"] >= 0x3 && $frame["opcode"] <= 0x7 || $frame["opcode"] >= 0xb) {
             return array("success" => false, "error" => HTTP::HTTPTranslate("Invalid frame detected.  Bad opcode 0x%02X.", $frame["opcode"]), "errorcode" => "bad_frame_opcode");
         }
         // No extension support (yet).
         if ($frame["rsv1"] || $frame["rsv2"] || $frame["rsv3"]) {
             return array("success" => false, "error" => HTTP::HTTPTranslate("Invalid frame detected.  One or more reserved extension bits are set."), "errorcode" => "bad_reserved_bits_set");
         }
         if ($frame["opcode"] >= 0x8) {
             // Handle the control frame.
             if (!$frame["fin"]) {
                 return array("success" => false, "error" => HTTP::HTTPTranslate("Invalid frame detected.  Fragmented control frame was received."), "errorcode" => "bad_control_frame");
             }
             if ($frame["opcode"] === self::FRAMETYPE_CONNECTION_CLOSE) {
                 if ($this->state === self::STATE_CLOSE) {
                     // Already sent the close state.
                     @fclose($this->fp);
                     $this->fp = false;
                     return array("success" => false, "error" => HTTP::HTTPTranslate("Connection closed by peer."), "errorcode" => "connection_closed");
                 } else {
                     // Change the state to close and send the connection close response to the peer at the appropriate time.
                     if ($this->closemode === self::CLOSE_IMMEDIATELY) {
                         $this->writemessages = array();
                     } else {
                         if ($this->closemode === self::CLOSE_AFTER_CURRENT_MESSAGE) {
                             $this->writemessages = array_slice($this->writemessages, 0, 1);
                         }
                     }
                     $this->state = self::STATE_CLOSE;
                     $result = $this->Write("", self::FRAMETYPE_CONNECTION_CLOSE);
                     if (!$result["success"]) {
                         return $result;
                     }
                 }
             } else {
                 if ($frame["opcode"] === self::FRAMETYPE_PING) {
                     if ($this->state !== self::STATE_CLOSE) {
                         // Received a ping.  Respond with a pong with the same payload.
                         $result = $this->Write($frame["payload"], self::FRAMETYPE_PONG, true, false, 0);
                         if (!$result["success"]) {
                             return $result;
                         }
                     }
                 } else {
                     if ($frame["opcode"] === self::FRAMETYPE_PONG) {
                         // Do nothing.
                     }
                 }
             }
         } else {
             // Add this frame to the read message queue.
             $lastcompleted = !count($this->readmessages) || $this->readmessages[count($this->readmessages) - 1]["fin"];
             if ($lastcompleted) {
                 // Make sure the new frame is the start of a fragment or is not fragemented.
                 if ($frame["opcode"] === self::FRAMETYPE_CONTINUATION) {
                     return array("success" => false, "error" => HTTP::HTTPTranslate("Invalid frame detected.  Fragment continuation frame was received at the start of a fragment."), "errorcode" => "bad_continuation_frame");
                 }
                 $this->readmessages[] = $frame;
             } else {
                 // Make sure the frame is a continuation frame.
                 if ($frame["opcode"] !== self::FRAMETYPE_CONTINUATION) {
                     return array("success" => false, "error" => HTTP::HTTPTranslate("Invalid frame detected.  Fragment continuation frame was not received for a fragment."), "errorcode" => "missing_continuation_frame");
                 }
                 $this->readmessages[count($this->readmessages) - 1]["fin"] = $frame["fin"];
                 $this->readmessages[count($this->readmessages) - 1]["payload"] .= $frame["payload"];
             }
             if ($this->maxreadmessagesize !== false && strlen($this->readmessages[count($this->readmessages) - 1]["payload"]) > $this->maxreadmessagesize) {
                 return array("success" => false, "error" => HTTP::HTTPTranslate("Peer sent a single message exceeding %s bytes of data.", $this->maxreadmessagesize), "errorcode" => "max_read_message_size_exceeded");
             }
         }
         //var_dump($frame);
     }
     return array("success" => true);
 }
开发者ID:watsonweber,项目名称:ultimate-web-scraper,代码行数:77,代码来源:websocket.php

示例3: get_check_curl_multi_init_key

 function get_check_curl_multi_init_key($ch)
 {
     global $curl_init__map;
     $key = get_curl_multi_init_key($ch);
     if (!isset($curl_multi_init__map[$key])) {
         throw new Exception(HTTP::HTTPTranslate("cURL Emulator:  Unable to find key mapping for resource."));
     }
     return $key;
 }
开发者ID:Scraps-Git,项目名称:PingPong,代码行数:9,代码来源:emulate_curl.php

示例4: Process

 public function Process($url, $profile = "auto", $tempoptions = array())
 {
     $startts = microtime(true);
     $redirectts = $startts;
     if (isset($tempoptions["timeout"])) {
         $timeout = $tempoptions["timeout"];
     } else {
         if (isset($this->data["httpopts"]["timeout"])) {
             $timeout = $this->data["httpopts"]["timeout"];
         } else {
             $timeout = false;
         }
     }
     if (!isset($this->data["httpopts"]["headers"])) {
         $this->data["httpopts"]["headers"] = array();
     }
     $this->data["httpopts"]["headers"] = HTTP::NormalizeHeaders($this->data["httpopts"]["headers"]);
     unset($this->data["httpopts"]["method"]);
     unset($this->data["httpopts"]["write_body_callback"]);
     unset($this->data["httpopts"]["body"]);
     unset($this->data["httpopts"]["postvars"]);
     unset($this->data["httpopts"]["files"]);
     $httpopts = $this->data["httpopts"];
     $numfollow = $this->data["maxfollow"];
     $numredirects = 0;
     $totalrawsendsize = 0;
     if (!isset($tempoptions["headers"])) {
         $tempoptions["headers"] = array();
     }
     $tempoptions["headers"] = HTTP::NormalizeHeaders($tempoptions["headers"]);
     if (isset($tempoptions["headers"]["Referer"])) {
         $this->data["referer"] = $tempoptions["headers"]["Referer"];
     }
     // If a referrer is specified, use it to generate an absolute URL.
     if ($this->data["referer"] != "") {
         $url = HTTP::ConvertRelativeToAbsoluteURL($this->data["referer"], $url);
     }
     $urlinfo = HTTP::ExtractURL($url);
     do {
         if (!isset($this->data["allowedprotocols"][$urlinfo["scheme"]]) || !$this->data["allowedprotocols"][$urlinfo["scheme"]]) {
             return array("success" => false, "error" => HTTP::HTTPTranslate("Protocol '%s' is not allowed in '%s'.", $urlinfo["scheme"], $url), "errorcode" => "allowed_protocols");
         }
         $filename = HTTP::ExtractFilename($urlinfo["path"]);
         $pos = strrpos($filename, ".");
         $fileext = $pos !== false ? strtolower(substr($filename, $pos + 1)) : "";
         // Set up some standard headers.
         $headers = array();
         $profile = strtolower($profile);
         $tempprofile = explode("-", $profile);
         if (count($tempprofile) == 2) {
             $profile = $tempprofile[0];
             $fileext = $tempprofile[1];
         }
         if (substr($profile, 0, 2) == "ie" || $profile == "auto" && substr($this->data["useragent"], 0, 2) == "ie") {
             if ($fileext == "css") {
                 $headers["Accept"] = "text/css";
             } else {
                 if ($fileext == "png" || $fileext == "jpg" || $fileext == "jpeg" || $fileext == "gif" || $fileext == "svg") {
                     $headers["Accept"] = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
                 } else {
                     if ($fileext == "js") {
                         $headers["Accept"] = "application/javascript, */*;q=0.8";
                     } else {
                         if ($this->data["referer"] != "" || $fileext == "" || $fileext == "html" || $fileext == "xhtml" || $fileext == "xml") {
                             $headers["Accept"] = "text/html, application/xhtml+xml, */*";
                         } else {
                             $headers["Accept"] = "*/*";
                         }
                     }
                 }
             }
             $headers["Accept-Language"] = "en-US";
             $headers["User-Agent"] = HTTP::GetUserAgent(substr($profile, 0, 2) == "ie" ? $profile : $this->data["useragent"]);
         } else {
             if ($profile == "firefox" || $profile == "auto" && $this->data["useragent"] == "firefox") {
                 if ($fileext == "css") {
                     $headers["Accept"] = "text/css,*/*;q=0.1";
                 } else {
                     if ($fileext == "png" || $fileext == "jpg" || $fileext == "jpeg" || $fileext == "gif" || $fileext == "svg") {
                         $headers["Accept"] = "image/png,image/*;q=0.8,*/*;q=0.5";
                     } else {
                         if ($fileext == "js") {
                             $headers["Accept"] = "*/*";
                         } else {
                             $headers["Accept"] = "text/html, application/xhtml+xml, */*";
                         }
                     }
                 }
                 $headers["Accept-Language"] = "en-us,en;q=0.5";
                 $headers["Cache-Control"] = "max-age=0";
                 $headers["User-Agent"] = HTTP::GetUserAgent("firefox");
             } else {
                 if ($profile == "opera" || $profile == "auto" && $this->data["useragent"] == "opera") {
                     // Opera has the right idea:  Just send the same thing regardless of the request type.
                     $headers["Accept"] = "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1";
                     $headers["Accept-Language"] = "en-US,en;q=0.9";
                     $headers["Cache-Control"] = "no-cache";
                     $headers["User-Agent"] = HTTP::GetUserAgent("opera");
                 } else {
                     if ($profile == "safari" || $profile == "chrome" || $profile == "auto" && ($this->data["useragent"] == "safari" || $this->data["useragent"] == "chrome")) {
//.........这里部分代码省略.........
开发者ID:harrylongworth,项目名称:tv-bb,代码行数:101,代码来源:web_browser.php


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