當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HTTP::HeaderNameCleanup方法代碼示例

本文整理匯總了PHP中HTTP::HeaderNameCleanup方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTTP::HeaderNameCleanup方法的具體用法?PHP HTTP::HeaderNameCleanup怎麽用?PHP HTTP::HeaderNameCleanup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HTTP的用法示例。


在下文中一共展示了HTTP::HeaderNameCleanup方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: curl_exec


//.........這裏部分代碼省略.........
     $options["sslopts"]["capture_peer_cert"] = isset($curl_init__map[$key]["options"][CURLOPT_CERTINFO]) ? $curl_init__map[$key]["options"][CURLOPT_CERTINFO] : false;
     // Set the method.
     if (isset($curl_init__map[$key]["options"][CURLOPT_UPLOAD]) && (bool) $curl_init__map[$key]["options"][CURLOPT_UPLOAD]) {
         $options["method"] = "PUT";
     } else {
         $options["method"] = $curl_init__map[$key]["method"];
     }
     // Set the HTTP version.
     if (isset($curl_init__map[$key]["options"][CURLOPT_HTTP_VERSION])) {
         if ($curl_init__map[$key]["options"][CURLOPT_HTTP_VERSION] == CURL_HTTP_VERSION_1_0) {
             $options["httpver"] = "1.0";
         } else {
             if ($curl_init__map[$key]["options"][CURLOPT_HTTP_VERSION] == CURL_HTTP_VERSION_1_1) {
                 $options["httpver"] = "1.1";
             }
         }
     }
     // Set rate limits.
     if (isset($curl_init__map[$key]["options"][CURLOPT_MAX_RECV_SPEED_LARGE])) {
         $options["recvratelimit"] = $curl_init__map[$key]["options"][CURLOPT_MAX_RECV_SPEED_LARGE];
     }
     if (isset($curl_init__map[$key]["options"][CURLOPT_MAX_SEND_SPEED_LARGE])) {
         $options["sendratelimit"] = $curl_init__map[$key]["options"][CURLOPT_MAX_SEND_SPEED_LARGE];
     }
     // Set headers.
     $options["headers"] = array();
     $options["headers"]["Accept"] = "*/*";
     if (isset($curl_init__map[$key]["options"][CURLOPT_HTTPHEADER]) && is_array($curl_init__map[$key]["options"][CURLOPT_HTTPHEADER])) {
         foreach ($curl_init__map[$key]["options"][CURLOPT_HTTPHEADER] as $header) {
             $pos = strpos($header, ":");
             if ($pos !== false) {
                 $val = ltrim(substr($header, $pos + 1));
                 if ($val == "") {
                     unset($options["headers"][HTTP::HeaderNameCleanup(substr($header, 0, $pos))]);
                 } else {
                     $options["headers"][HTTP::HeaderNameCleanup(substr($header, 0, $pos))] = $val;
                 }
             }
         }
     }
     if (isset($curl_init__map[$key]["options"][CURLOPT_USERAGENT])) {
         $options["headers"]["User-Agent"] = $curl_init__map[$key]["options"][CURLOPT_USERAGENT];
     }
     if (isset($curl_init__map[$key]["options"][CURLOPT_COOKIE])) {
         $options["headers"]["Cookie"] = $curl_init__map[$key]["options"][CURLOPT_COOKIE];
     }
     if (isset($curl_init__map[$key]["options"][CURLOPT_RANGE])) {
         $options["headers"]["Range"] = "bytes=" . $curl_init__map[$key]["options"][CURLOPT_RANGE];
     }
     if (isset($curl_init__map[$key]["options"][CURLOPT_RESUME_FROM])) {
         $options["headers"]["Range"] = "bytes=" . $curl_init__map[$key]["options"][CURLOPT_RESUME_FROM] . "-";
     }
     if (isset($curl_init__map[$key]["options"][CURLOPT_TIMECONDITION]) && isset($curl_init__map[$key]["options"][CURLOPT_TIMEVALUE])) {
         if ($curl_init__map[$key]["options"][CURLOPT_TIMECONDITION] == CURL_TIMECOND_IFMODSINCE) {
             $options["headers"]["If-Modified-Since"] = gmdate("D, d M Y H:i:s", $curl_init__map[$key]["options"][CURLOPT_TIMEVALUE]) . " GMT";
         } else {
             if ($curl_init__map[$key]["options"][CURLOPT_TIMECONDITION] == CURL_TIMECOND_IFUNMODSINCE) {
                 $options["headers"]["If-Unmodified-Since"] = gmdate("D, d M Y H:i:s", $curl_init__map[$key]["options"][CURLOPT_TIMEVALUE]) . " GMT";
             }
         }
     }
     // Set POST variables and files.
     if (isset($curl_init__map[$key]["options"][CURLOPT_POSTFIELDS])) {
         $postvars = $curl_init__map[$key]["options"][CURLOPT_POSTFIELDS];
         if (is_string($postvars)) {
             $postvars2 = array();
開發者ID:Scraps-Git,項目名稱:PingPong,代碼行數:67,代碼來源:emulate_curl.php


注:本文中的HTTP::HeaderNameCleanup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。