本文整理汇总了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.
//.........这里部分代码省略.........
示例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();