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


PHP http_chunked_decode函数代码示例

本文整理汇总了PHP中http_chunked_decode函数的典型用法代码示例。如果您正苦于以下问题:PHP http_chunked_decode函数的具体用法?PHP http_chunked_decode怎么用?PHP http_chunked_decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _getTest

 protected function _getTest($path, $length, $type, $status, $expected, $message = null, $encoding = null)
 {
     $this->prepareForRequest();
     $context = new stdClass();
     $context->request = new org_tubepress_api_http_HttpRequest(org_tubepress_api_http_HttpRequest::HTTP_METHOD_GET, $this->_server . "/{$path}");
     $context->request->setHeader(org_tubepress_api_http_HttpRequest::HTTP_HEADER_USER_AGENT, 'TubePress');
     $result = $this->_sut->execute($context);
     $this->assertTrue($result, "Command did not return true that it had handled request ({$result})");
     $response = $context->response;
     $this->assertTrue($response instanceof org_tubepress_api_http_HttpResponse, 'Reponse is not of type HttpResponse');
     $actualContentType = $response->getHeaderValue(org_tubepress_api_http_HttpMessage::HTTP_HEADER_CONTENT_TYPE);
     $this->assertTrue($actualContentType === $type || $actualContentType === "{$type}; charset=utf-8", "Expected Content-Type {$type} but got {$actualContentType}");
     $encoded = $response->getHeaderValue(org_tubepress_api_http_HttpMessage::HTTP_HEADER_CONTENT_ENCODING);
     $this->assertEquals($encoding, $encoded, "Expected encoding {$encoding} but got {$encoded}");
     $this->assertEquals($status, $response->getStatusCode(), "Expected status code {$status} but got " . $response->getStatusCode());
     $entity = $response->getEntity();
     $this->assertTrue($entity instanceof org_tubepress_api_http_HttpEntity);
     if ($response->getHeaderValue(org_tubepress_api_http_HttpResponse::HTTP_HEADER_TRANSFER_ENCODING) === 'chunked') {
         $data = @http_chunked_decode($entity->getContent());
         if ($data === false) {
             $data = $entity->getContent();
         }
     } else {
         $data = $entity->getContent();
     }
     $this->assertEquals($expected, $data);
 }
开发者ID:nidalhajaj,项目名称:tubepress,代码行数:27,代码来源:AbstractHttpTransportTest.php

示例2: test_functions

/**
 * Test Http functions.
 */
function test_functions()
{
    http_cache_last_modified();
    http_chunked_decode();
    http_deflate();
    http_inflate();
    http_build_cookie();
    http_date();
    http_get_request_body_stream();
    http_get_request_body();
    http_get_request_headers();
    http_match_etag();
    http_match_modified();
    http_match_request_header();
    http_support();
    http_negotiate_charset();
    http_negotiate_content_type();
    http_negotiate_language();
    ob_deflatehandler();
    ob_etaghandler();
    ob_inflatehandler();
    http_parse_cookie();
    http_parse_headers();
    http_parse_message();
    http_parse_params();
    http_persistent_handles_clean();
    http_persistent_handles_count();
    http_persistent_handles_ident();
    http_get();
    http_head();
    http_post_data();
    http_post_fields();
    http_put_data();
    http_put_file();
    http_put_stream();
    http_request_body_encode();
    http_request_method_exists();
    http_request_method_name();
    http_request_method_register();
    http_request_method_unregister();
    http_request();
    http_redirect();
    http_send_content_disposition();
    http_send_content_type();
    http_send_data();
    http_send_file();
    http_send_last_modified();
    http_send_status();
    http_send_stream();
    http_throttle();
    http_build_str();
    http_build_url();
}
开发者ID:jkribeiro,项目名称:PHPHttpCompatibility,代码行数:56,代码来源:snippets.php

示例3: _doExecute

 /**
  * Send a HTTP request to a URI using HTTP extension.
  *
  * Does not support non-blocking.
  *
  * @param string    $url  The URL to handle.
  * @param str|array $args Optional. Override the defaults.
  *
  * @return array 'headers', 'body', 'cookies' and 'response' keys.
  */
 protected function _doExecute($url, $args)
 {
     switch ($args[org_tubepress_impl_http_HttpClientChain::ARGS_METHOD]) {
         case org_tubepress_api_http_HttpClient::HTTP_METHOD_POST:
             $args[org_tubepress_impl_http_HttpClientChain::ARGS_METHOD] = HTTP_METH_POST;
             break;
         case org_tubepress_api_http_HttpClient::HTTP_METHOD_PUT:
             $args[org_tubepress_impl_http_HttpClientChain::ARGS_METHOD] = HTTP_METH_PUT;
             break;
         case org_tubepress_api_http_HttpClient::HTTP_METHOD_GET:
         default:
             $args[org_tubepress_impl_http_HttpClientChain::ARGS_METHOD] = HTTP_METH_GET;
     }
     $urlAsArray = parse_url($url);
     if ('http' != $urlAsArray['scheme'] && 'https' != $urlAsArray['scheme']) {
         $url = preg_replace('|^' . preg_quote($urlAsArray['scheme'], '|') . '|', 'http', $url);
     }
     $sslVerify = isset($args[org_tubepress_impl_http_HttpClientChain::ARGS_SSL_VERIFY]) && $args[org_tubepress_impl_http_HttpClientChain::ARGS_SSL_VERIFY];
     $args[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT] = (int) ceil($args[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT]);
     $options = array('timeout' => $args[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT], 'connecttimeout' => $args[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT], 'redirect' => 5, 'useragent' => $args[org_tubepress_impl_http_HttpClientChain::ARGS_USER_AGENT], 'headers' => $args[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS], 'ssl' => array('verifypeer' => $sslVerify, 'verifyhost' => $sslVerify));
     $strResponse = @http_request($args[org_tubepress_impl_http_HttpClientChain::ARGS_METHOD], $url, $args[org_tubepress_impl_http_HttpClientChain::ARGS_BODY], $options, $info);
     // Error may still be set, Response may return headers or partial document, and error
     // contains a reason the request was aborted, eg, timeout expired or max-redirects reached.
     if (false === $strResponse || !empty($info['error'])) {
         throw new Exception($info['response_code'] . ': ' . $info['error']);
     }
     $headersBody = self::_breakRawStringResponseIntoHeaderAndBody($strResponse);
     $theHeaders = $headersBody[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS];
     $theBody = $headersBody[org_tubepress_impl_http_HttpClientChain::ARGS_BODY];
     unset($headersBody);
     $theHeaders = self::_getProcessedHeaders($theHeaders);
     if (!empty($theBody) && isset($theHeaders['headers']['transfer-encoding']) && 'chunked' == $theHeaders['headers']['transfer-encoding']) {
         $theBody = @http_chunked_decode($theBody);
     }
     if (true === $args['decompress'] && true === org_tubepress_impl_http_clientimpl_Encoding::shouldDecode($theHeaders['headers'])) {
         $theBody = http_inflate($theBody);
     }
     return array('headers' => $theHeaders['headers'], 'body' => $theBody, 'response' => $theHeaders['response'], 'cookies' => $theHeaders['cookies']);
 }
开发者ID:Ashleyotero,项目名称:oldest-old,代码行数:49,代码来源:ExtHttpCommand.class.php

示例4: run_request

function run_request($Request, &$Response)
{
    list(, $host) = explode('Host: ', $Request, 2);
    list($host, ) = explode("\r\n", $host, 2);
    list($host, $port) = explode(':', $host, 2);
    $open = fsockopen($host, $port);
    fputs($open, $Request);
    while (!feof($open)) {
        $Result .= fgets($open, 4096);
    }
    fclose($open);
    list($Response, $Html) = @explode("\r\n\r\n", $Result, 2);
    if (preg_match("/transfer\\-encoding\\: chunked/i", $Response)) {
        $Html = http_chunked_decode($Html);
    }
    if (preg_match("/Content\\-Encoding\\: gzip/i", $Response)) {
        $Response = preg_replace("/Content\\-Encoding: gzip\\s+/isU", "", $Response);
        $Html = gzinflate(substr($Html, 10));
    }
    return $Html;
}
开发者ID:joginvik,项目名称:gvindelen,代码行数:21,代码来源:Download.php

示例5: request

 /**
  * Send a HTTP request to a URI using HTTP extension.
  *
  * Does not support non-blocking.
  *
  * @access public
  * @since 2.7
  *
  * @param string $url
  * @param str|array $args Optional. Override the defaults.
  * @return array 'headers', 'body', and 'response' keys.
  */
 function request($url, $args = array())
 {
     $defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null);
     $r = wp_parse_args($args, $defaults);
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     } else {
         if (isset($r['headers']['user-agent'])) {
             $r['user-agent'] = $r['headers']['user-agent'];
             unset($r['headers']['user-agent']);
         }
     }
     switch ($r['method']) {
         case 'POST':
             $r['method'] = HTTP_METH_POST;
             break;
         case 'HEAD':
             $r['method'] = HTTP_METH_HEAD;
             break;
         case 'GET':
         default:
             $r['method'] = HTTP_METH_GET;
     }
     $arrURL = parse_url($url);
     if ('http' != $arrURL['scheme'] || 'https' != $arrURL['scheme']) {
         $url = str_replace($arrURL['scheme'], 'http', $url);
     }
     $options = array('timeout' => $r['timeout'], 'connecttimeout' => $r['timeout'], 'redirect' => $r['redirection'], 'useragent' => $r['user-agent'], 'headers' => $r['headers']);
     if (!defined('WP_DEBUG') || defined('WP_DEBUG') && false === WP_DEBUG) {
         //Emits warning level notices for max redirects and timeouts
         $strResponse = @http_request($r['method'], $url, $r['body'], $options, $info);
     } else {
         $strResponse = http_request($r['method'], $url, $r['body'], $options, $info);
     }
     //Emits warning level notices for max redirects and timeouts
     if (false === $strResponse || !empty($info['error'])) {
         //Error may still be set, Response may return headers or partial document, and error contains a reason the request was aborted, eg, timeout expired or max-redirects reached
         return new WP_Error('http_request_failed', $info['response_code'] . ': ' . $info['error']);
     }
     if (!$r['blocking']) {
         return array('headers' => array(), 'body' => '', 'response' => array('code', 'message'));
     }
     list($theHeaders, $theBody) = explode("\r\n\r\n", $strResponse, 2);
     $theHeaders = WP_Http::processHeaders($theHeaders);
     if (!empty($theBody) && isset($theHeaders['headers']['transfer-encoding']) && 'chunked' == $theHeaders['headers']['transfer-encoding']) {
         if (!defined('WP_DEBUG') || defined('WP_DEBUG') && false === WP_DEBUG) {
             $theBody = @http_chunked_decode($theBody);
         } else {
             $theBody = http_chunked_decode($theBody);
         }
     }
     if (true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders)) {
         $theBody = http_inflate($theBody);
     }
     $theResponse = array();
     $theResponse['code'] = $info['response_code'];
     $theResponse['message'] = get_status_header_desc($info['response_code']);
     return array('headers' => $theHeaders['headers'], 'body' => $theBody, 'response' => $theResponse);
 }
开发者ID:blowery,项目名称:wordpress,代码行数:72,代码来源:http.php

示例6: putfile


//.........这里部分代码省略.........
    $errno = 0;
    $errstr = '';
    $hosts = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port);
    $fp = @stream_socket_client($hosts, $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
    if (!$fp) {
        if (!function_exists('stream_socket_client')) {
            html_error('[ERROR] stream_socket_client() is disabled.');
        }
        $dis_host = !empty($proxyHost) ? $proxyHost : $host;
        $dis_port = !empty($proxyPort) ? $proxyPort : $port;
        html_error(sprintf(lang(88), $dis_host, $dis_port));
    }
    if ($errno || $errstr) {
        $lastError = $errstr;
        return false;
    }
    if ($proxy) {
        echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />PUT: <b>' . htmlspecialchars($url) . "</b>...<br />\n";
    } else {
        echo '<p>' . sprintf(lang(90), $host, $port) . '</p>';
    }
    echo lang(104) . ' <b>' . htmlspecialchars($filename) . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMbOrGb($fileSize) . '</b>...<br />';
    $GLOBALS['id'] = md5(time() * rand(0, 10));
    require TEMPLATE_DIR . '/uploadui.php';
    flush();
    $timeStart = microtime(true);
    $chunkSize = GetChunkSize($fileSize);
    fwrite($fp, $request);
    fflush($fp);
    $fs = fopen($file, 'r');
    $totalsend = $time = $lastChunkTime = 0;
    while (!feof($fs) && !$errno && !$errstr) {
        $data = fread($fs, $chunkSize);
        if ($data === false) {
            fclose($fs);
            fclose($fp);
            html_error(lang(112));
        }
        $sendbyte = @fwrite($fp, $data);
        fflush($fp);
        if ($sendbyte === false || strlen($data) > $sendbyte) {
            fclose($fs);
            fclose($fp);
            html_error(lang(113));
        }
        $totalsend += $sendbyte;
        $time = microtime(true) - $timeStart;
        $chunkTime = $time - $lastChunkTime;
        $chunkTime = $chunkTime > 0 ? $chunkTime : 1;
        $lastChunkTime = $time;
        $speed = round($sendbyte / 1024 / $chunkTime, 2);
        $percent = round($totalsend / $fileSize * 100, 2);
        echo "<script type='text/javascript'>pr('{$percent}', '" . bytesToKbOrMbOrGb($totalsend) . "', '{$speed}');</script>\n";
        flush();
    }
    if ($errno || $errstr) {
        $lastError = $errstr;
        return false;
    }
    fclose($fs);
    fflush($fp);
    $llen = 0;
    $header = '';
    do {
        $header .= fgets($fp, 16384);
        $len = strlen($header);
        if (!$header || $len == $llen) {
            $lastError = lang(91);
            stream_socket_shutdown($fp, STREAM_SHUT_RDWR);
            fclose($fp);
            return false;
        }
        $llen = $len;
    } while (strpos($header, $nn . $nn) === false);
    // Array for active stream filters
    $sFilters = array();
    if (stripos($header, "\nTransfer-Encoding: chunked") !== false && in_array('dechunk', stream_get_filters())) {
        $sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ);
    }
    // Add built-in dechunk filter
    $page = '';
    do {
        $data = @fread($fp, 16384);
        if ($data == '') {
            break;
        }
        $page .= $data;
    } while (!feof($fp) && strlen($data) > 0);
    stream_socket_shutdown($fp, STREAM_SHUT_RDWR);
    fclose($fp);
    if (stripos($header, "\nTransfer-Encoding: chunked") !== false && empty($sFilters['dechunk']) && function_exists('http_chunked_decode')) {
        $dechunked = http_chunked_decode($page);
        if ($dechunked !== false) {
            $page = $dechunked;
        }
        unset($dechunked);
    }
    $page = $header . $page;
    return $page;
}
开发者ID:Transcodes,项目名称:rapidleech,代码行数:101,代码来源:http.php

示例7: geturl


//.........这里部分代码省略.........
            if (@file_exists($saveToFile)) {
                $saveToFile = dirname($saveToFile) . PATH_SPLITTER . time() . '_' . basename($saveToFile);
            }
            $fs = @fopen($saveToFile, 'wb');
            if (!$fs) {
                $secondName = dirname($saveToFile) . PATH_SPLITTER . str_replace(':', '', str_replace('?', '', basename($saveToFile)));
                $fs = @fopen($secondName, 'wb');
                if (!$fs) {
                    $lastError = sprintf(lang(101), basename($saveToFile), dirname($saveToFile)) . '<br />' . lang(102) . '<br /><a href="javascript:location.reload();">' . lang(103) . '</a>';
                    return FALSE;
                }
            }
        }
        flock($fs, LOCK_EX);
        if ($Resume['use'] === TRUE && stripos($header, "\nContent-Range: ") !== false) {
            list($temp, $Resume['range']) = explode(' ', trim(cut_str($header, "\nContent-Range: ", "\n")));
            list($Resume['range'], $fileSize) = explode('/', $Resume['range']);
            $fileSize = bytesToKbOrMbOrGb($fileSize);
        } else {
            $fileSize = bytesToKbOrMbOrGb($bytesTotal);
        }
        $chunkSize = GetChunkSize($bytesTotal);
        echo lang(104) . ' <b>' . basename($saveToFile) . '</b>, ' . lang(56) . ' <b>' . $fileSize . '</b>...<br />';
        //$scriptStarted = false;
        require_once TEMPLATE_DIR . '/transloadui.php';
        if ($Resume['use'] === TRUE) {
            $received = bytesToKbOrMbOrGb(filesize($saveToFile));
            $percent = round($Resume['from'] / ($bytesTotal + $Resume['from']) * 100, 2);
            echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . $received . "', '0');</script>";
            //$scriptStarted = true;
            flush();
        }
    } else {
        $page = '';
    }
    $time = $last = $lastChunkTime = 0;
    do {
        $data = @fread($fp, $saveToFile ? $chunkSize : 16384);
        // 16384 saw this value in Pear HTTP_Request2 package // (fix - szal) using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!)
        if ($data == '') {
            break;
        }
        if ($saveToFile) {
            $bytesSaved = fwrite($fs, $data);
            if ($bytesSaved !== false && strlen($data) == $bytesSaved) {
                //if ($bytesSaved > - 1) {
                $bytesReceived += $bytesSaved;
            } else {
                $lastError = sprintf(lang(105), basename($saveToFile));
                unlink($saveToFile);
                return false;
            }
            if ($bytesReceived >= $bytesTotal) {
                $percent = 100;
            } else {
                $percent = @round(($bytesReceived + $Resume['from']) / ($bytesTotal + $Resume['from']) * 100, 2);
            }
            if ($bytesReceived > $last + $chunkSize) {
                $received = bytesToKbOrMbOrGb($bytesReceived + $Resume['from']);
                $time = getmicrotime() - $timeStart;
                $chunkTime = $time - $lastChunkTime;
                $chunkTime = $chunkTime ? $chunkTime : 1;
                $lastChunkTime = $time;
                $speed = @round($chunkSize / 1024 / $chunkTime, 2);
                /*if (!$scriptStarted) {
                			echo('<script type="text/javascript">');
                			$scriptStarted = true;
                		}*/
                echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . $received . "', '" . $speed . "');</script>";
                $last = $bytesReceived;
            }
        } else {
            $page .= $data;
        }
    } while (strlen($data) > 0);
    //echo('</script>');
    if ($saveToFile) {
        flock($fs, LOCK_UN);
        fclose($fs);
        if ($bytesReceived <= 0) {
            $lastError = lang(106);
            fclose($fp);
            return FALSE;
        }
    }
    fclose($fp);
    if ($saveToFile) {
        return array('time' => sec2time(round($time)), 'speed' => @round($bytesTotal / 1024 / (getmicrotime() - $timeStart), 2), 'received' => true, 'size' => $fileSize, 'bytesReceived' => $bytesReceived + $Resume['from'], 'bytesTotal' => $bytesTotal + $Resume['from'], 'file' => $saveToFile);
    } else {
        if (stripos($header, "\nTransfer-Encoding: chunked") !== false && function_exists('http_chunked_decode')) {
            $dechunked = http_chunked_decode($page);
            if ($dechunked !== false) {
                $page = $dechunked;
            }
            unset($dechunked);
        }
        $page = $header . $page;
        return $page;
    }
}
开发者ID:mewtutorial,项目名称:RapidTube,代码行数:101,代码来源:http.php

示例8: curlRequestAsync

 /**
  * Executes CURL async request.
  *
  * @param string $url URL.
  * @param array $params List of request params.
  * @param string $type Type of the request (GET, POST, ...).
  * @param int $timeout Timeout in seconds.
  *
  * @return type
  */
 public static function curlRequestAsync($url, $params, $type = self::POST, $timeout = 30)
 {
     $postParams = array();
     foreach ($params as $key => &$val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $postParams[] = $key . '=' . urlencode($val);
     }
     $postString = implode('&', $postParams);
     $parts = parse_url($url);
     $port = isset($parts['port']) ? (int) $parts['port'] : 80;
     $fp = fsockopen($parts['host'], $port, $errno, $errstr, $timeout);
     // Data goes in the path for a GET request
     if ($type == self::GET) {
         $parts['path'] .= '?' . $postString;
     }
     $request = "{$type} " . $parts['path'] . " HTTP/1.1\r\n";
     $request .= "Host: " . $parts['host'] . "\r\n";
     if ($type == self::POST) {
         $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
         $request .= "Content-Length: " . strlen($postString) . "\r\n";
     }
     $request .= "Connection: Close\r\n";
     $request .= "\r\n";
     // Data goes in the request body for a POST request
     if ($type == self::POST && isset($postString)) {
         $request .= $postString;
     }
     fwrite($fp, $request);
     $response = "";
     while (!feof($fp) && ($result = fgets($fp))) {
         $response .= $result;
     }
     fclose($fp);
     list($respHeader, $respBody) = preg_split("/\\R\\R/", $response, 2);
     $headers = array_map(array('self', "pair"), explode("\r\n", $respHeader));
     $headerList = array();
     foreach ($headers as $value) {
         $headerList[$value['key']] = $value['value'];
     }
     return array('request' => $request, 'response' => array('header' => $respHeader, 'headerList' => $headerList, 'body' => trim(http_chunked_decode($respBody))), 'errno' => $errno, 'errstr' => $errstr);
 }
开发者ID:pomed,项目名称:Framework,代码行数:53,代码来源:Http.php

示例9: unchunk2

 private function unchunk2($chunk)
 {
     if (!function_exists('http-chunked-decode')) {
         $pos = 0;
         $len = strlen($chunk);
         $dechunk = null;
         while ($pos < $len && ($chunkLenHex = substr($chunk, $pos, ($newlineAt = strpos($chunk, "\n", $pos + 1)) - $pos))) {
             if (!$this->is_hex($chunkLenHex)) {
                 //trigger_error('Value is not properly chunk encoded', E_USER_WARNING);
                 return $chunk;
             }
             $pos = $newlineAt + 1;
             $chunkLen = hexdec(rtrim($chunkLenHex, "\r\n"));
             $dechunk .= substr($chunk, $pos, $chunkLen);
             $pos = strpos($chunk, "\n", $pos + $chunkLen) + 1;
         }
         return $dechunk;
     } else {
         return http_chunked_decode($result);
     }
 }
开发者ID:yxdj,项目名称:network,代码行数:21,代码来源:Http.php

示例10: parse

 /**
  * Parses the raw response
  *
  * @throws HTTPResponseException
  * @param string $data
  */
 protected function parse($data)
 {
     $pos = strpos($data, "\r\n\r\n");
     if (!$pos) {
         throw new HTTPResponseException("Couldn't parse response header!");
     }
     $header = substr($data, 0, $pos);
     $body = substr($data, $pos + 4);
     $this->parse_header($header);
     $enc = $this->get_header('content-encoding');
     if ($this->get_header('transfer-encoding') === 'chunked') {
         $body = http_chunked_decode($body);
     }
     $this->data = $body;
     unset($body, $header);
 }
开发者ID:poppa,项目名称:PLib,代码行数:22,代码来源:net.php

示例11: geturl


//.........这里部分代码省略.........
                $secondName = dirname($saveToFile) . PATH_SPLITTER . str_replace(":", "", str_replace("?", "", basename($saveToFile)));
                $fs = @fopen($secondName, "wb");
                if (!$fs) {
                    $lastError = $L->sprintf($L->say['_error_cantsave'], basename($saveToFile)) . '<br />' . $L->say['_error_trychmod'] . '<br /><a href="javascript:location.reload();">' . $L->say['_error_tryagain'] . '</a>';
                    return FALSE;
                }
            }
        }
        flock($fs, LOCK_EX);
        if ($Resume['use'] === TRUE && stripos($header, "\nContent-Range: ") !== false) {
            list($temp, $Resume['range']) = explode(' ', trim(cut_str($header, "\nContent-Range: ", "\n")));
            list($Resume['range'], $fileSize) = explode('/', $Resume['range']);
            $fileSize = bytesToKbOrMbOrGb($fileSize);
        } else {
            $fileSize = bytesToKbOrMbOrGb($bytesTotal);
        }
        $chunkSize = GetChunkSize($bytesTotal);
        $File_Name = basename($saveToFile);
        if (!empty($options["add_ext_5city"])) {
            $ext = "." . get_extension(basename($saveToFile));
            $File_Name = str_replace($ext, "", basename($saveToFile));
        }
        echo $L->sprintf($L->say['_saveprogres'], $File_Name, $ext, $fileSize) . '<br />';
        //$scriptStarted = false;
        require_once TEMPLATE_DIR . 'transloadui.php';
        if ($Resume['use'] === TRUE) {
            $received = bytesToKbOrMbOrGb(filesize($saveToFile));
            $percent = round($Resume['from'] / ($bytesTotal + $Resume['from']) * 100, 2);
            echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . $received . "', '0');</script>";
            //$scriptStarted = true;
            flush();
        }
    } else {
        $page = "";
    }
    $time = $last = $lastChunkTime = 0;
    do {
        $data = @fread($fp, $saveToFile ? $chunkSize : 16384);
        // 16384 saw this value in Pear HTTP_Request2 package // (fix - szal) using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!)
        if ($data == '') {
            break;
        }
        if ($saveToFile) {
            $bytesSaved = fwrite($fs, $data);
            if ($bytesSaved !== false && strlen($data) == $bytesSaved) {
                //if ($bytesSaved > - 1) {
                $bytesReceived += $bytesSaved;
            } else {
                $lastError = $L->sprintf($L->say['_error_imposible_record'], $saveToFile);
                unlink($saveToFile);
                return false;
            }
            if ($bytesReceived >= $bytesTotal) {
                $percent = 100;
            } else {
                $percent = @round(($bytesReceived + $Resume['from']) / ($bytesTotal + $Resume['from']) * 100, 2);
            }
            if ($bytesReceived > $last + $chunkSize) {
                $received = bytesToKbOrMbOrGb($bytesReceived + $Resume['from']);
                $time = getmicrotime() - $timeStart;
                $chunkTime = $time - $lastChunkTime;
                $chunkTime = $chunkTime ? $chunkTime : 1;
                $lastChunkTime = $time;
                $speed = @round($chunkSize / 1024 / $chunkTime, 2);
                /* if (!$scriptStarted) {
                	  echo('<script type="text/javascript">');
                	  $scriptStarted = true;
                	  } */
                echo "<script type='text/javascript'>pr('" . $percent . "', '" . $received . "', '" . $speed . "');</script>";
                $last = $bytesReceived;
            }
        } else {
            $page .= $data;
        }
    } while (strlen($data) > 0);
    //echo('</script>');
    if ($saveToFile) {
        flock($fs, LOCK_UN);
        fclose($fs);
        if ($bytesReceived <= 0) {
            $lastError = $L->say['_error_misc'];
            fclose($fp);
            return FALSE;
        }
    }
    fclose($fp);
    if ($saveToFile) {
        return array('time' => sec2time(round($time)), 'speed' => @round($bytesTotal / 1024 / (getmicrotime() - $timeStart), 2), 'received' => true, 'size' => $fileSize, 'bytesReceived' => $bytesReceived + $Resume['from'], 'bytesTotal' => $bytesTotal + $Resume['from'], 'file' => $saveToFile);
    } else {
        if (stripos($header, "\nTransfer-Encoding: chunked") !== false && function_exists('http_chunked_decode')) {
            $dechunked = http_chunked_decode($page);
            if ($dechunked !== false) {
                $page = $dechunked;
            }
            unset($dechunked);
        }
        $page = $header . $page;
        return $page;
    }
}
开发者ID:laiello,项目名称:rapidleech36b,代码行数:101,代码来源:http.php

示例12: CheckBack

 public function CheckBack($header)
 {
     $statuscode = intval(substr($header, 9, 3));
     if ($statuscode == 302) {
         $length = trim(cut_str($header, "\r\nContent-Length: ", "\r\n"));
         if (empty($length) || strlen($length) <= 6 && intval($length) <= 102400) {
             global $fp, $PHP_SELF;
             $page = '';
             while (strlen($data = @fread($fp, 16384)) > 0) {
                 $page .= $data;
             }
             if (stripos($header, "\r\nTransfer-Encoding: chunked") !== false && function_exists('http_chunked_decode')) {
                 $dechunked = http_chunked_decode($page);
                 if ($dechunked !== false) {
                     $page = $dechunked;
                 }
                 unset($dechunked);
             }
             $page = $header . $page;
             if (stripos($page, "\nyou need to wait 5 minutes between downloads") !== false) {
                 insert_timer(10, 'Auto retry download:');
                 //echo '<script type="text/javascript">location.reload();</script>';
                 echo "<center><form name='retryf' action='{$PHP_SELF}' method='POST'>\n";
                 if (!empty($_GET['proxy'])) {
                     $_GET['useproxy'] = 'on';
                 }
                 $post = array();
                 // I can't reload because firefox shows an anoying alertbox.
                 $post['filename'] = $_GET['filename'];
                 if (!empty($_GET['force_name'])) {
                     $post['force_name'] = $_GET['force_name'];
                 }
                 $post['host'] = $_GET['host'];
                 $post['path'] = $_GET['path'];
                 if (!empty($_GET['link'])) {
                     $post['link'] = $_GET['link'];
                 }
                 if (!empty($_GET['referer'])) {
                     $post['referer'] = $_GET['referer'];
                 }
                 if (!empty($_GET['post'])) {
                     $post['post'] = $_GET['post'];
                 }
                 $post = array_merge($this->DefaultParamArr(), array_map('urlencode', $post));
                 foreach ($post as $name => $input) {
                     echo "<input type='hidden' name='{$name}' id='{$name}' value='{$input}' />\n";
                 }
                 echo "<input type='submit' value='Try Again' />\n";
                 echo "</form></center><script type='text/javascript'>document.retryf.submit();</script><br />\n";
                 html_error('You need to wait 5 minutes between downloads.');
             } elseif (stripos($page, "\ndownload link expired") !== false) {
                 echo "<center><form action='{$PHP_SELF}' method='POST'>\n";
                 $post = $this->DefaultParamArr(cut_str($header, 'Location: ', "\r\n"));
                 $post['premium_acc'] = 'on';
                 foreach ($post as $name => $input) {
                     echo "<input type='hidden' name='{$name}' id='{$name}' value='{$input}' />\n";
                 }
                 echo "<input type='submit' value='Download Again' />\n";
                 echo "</form></center><br />\n";
                 html_error('Download link has expired.');
             }
         }
     }
 }
开发者ID:laiello,项目名称:rapidleech36b,代码行数:64,代码来源:bayfiles_com.php

示例13: CheckBack

 public function CheckBack($header)
 {
     if (stripos($header, "\nContent-Type: text/html") !== false) {
         global $fp, $sFilters;
         if (empty($fp) || !is_resource($fp)) {
             html_error('[filesflash_com] Cannot check download error.');
         }
         $is_chunked = stripos($header, "\nTransfer-Encoding: chunked") !== false;
         if (!isset($sFilters) || !is_array($sFilters)) {
             $sFilters = array();
         }
         if ($is_chunked && empty($sFilters['dechunk']) && in_array('dechunk', stream_get_filters())) {
             $sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ);
         }
         $body = stream_get_contents($fp);
         if ($is_chunked && empty($sFilters['dechunk']) && function_exists('http_chunked_decode')) {
             $dechunked = http_chunked_decode($body);
             if ($dechunked !== false) {
                 $body = $dechunked;
             }
             unset($dechunked);
         }
         is_present($body, 'Your IP address is not valid for this link.', '[filesflash_com] Your IP address is not valid for this link.');
         is_present($body, 'Your IP address is already downloading another link.', '[filesflash_com] Your IP address is already downloading another link.');
         is_present($body, 'Your link has expired.', '[filesflash_com] Your link has expired.');
         is_present($body, 'Interrupted free downloads cannot be resumed.', '[filesflash_com] Interrupted free downloads cannot be resumed.');
         html_error('[filesflash_com] Unknown download error.');
     }
 }
开发者ID:SheppeR,项目名称:rapidleech,代码行数:29,代码来源:filesflash_com.php

示例14: _decodeChunked

 /**
  * 解析 chunked 分块内容.
  * 
  * @access private
  * @param string $chunkedContent 分块内容.
  * @return string 不是分块, 原始内容.
  */
 private function _decodeChunked($chunkedContent)
 {
     if (function_exists('http_chunked_decode')) {
         $res = http_chunked_decode($chunkedContent);
         return FALSE === $res ? $chunkedContent : $res;
     }
     /*
      * 自己理解的 chunked 的格式为: 
      * 					第 1 段: 16进制大小字符\r\n
      * 							正文内容\r\n
      * 					第 2 段: 16进制大小字符\r\n
      * 							正文内容\r\n
      * 					结束:	0\r\n
      */
     $pos = 0;
     $len = strlen($chunkedContent);
     $decode = '';
     while ($pos < $len) {
         $offset = strpos($chunkedContent, "\n", $pos) - $pos;
         // 内容长度的 16 进制字符长度.
         $hex = substr($chunkedContent, $pos, $offset + 1);
         // 表示内容长度的 16 进制字符, 包含 \r\n.
         $len_hex = hexdec(rtrim(ltrim($hex, "0"), "\r\n")) + 2;
         // 内容长度, 转换为整数字节数.
         if (empty($len_hex)) {
             // 为空, 表示 chunked 已完成, 取到 0 时才会中止.
             break;
         }
         $decode .= rtrim(substr($chunkedContent, $pos + $offset + 1, $len_hex), "\r\n");
         // 拼接内容.
         $pos += $offset + $len_hex + 1;
     }
     return $decode;
 }
开发者ID:xiaofengwz,项目名称:wuyuan,代码行数:41,代码来源:SocketHttp.class.php

示例15: encode_respond

 private function encode_respond($buffer)
 {
     debugger($buffer, 'Buffer Entity');
     $header = $body = '';
     $p = strpos($buffer, "\r\n\r\n");
     // 去除头部信息
     if ($p > 0) {
         $header = substr($buffer, 0, $p);
         if ($p + 4 < strlen($buffer)) {
             $body = substr($buffer, $p + 4);
         }
     }
     // 如果header为续传标记则继续去除头部信息
     if ($header = 'HTTP/1.1 100 Continue') {
         $p = strpos($body, "\r\n\r\n");
         if ($p > 0) {
             $header = substr($body, 0, $p);
             if ($p + 4 < strlen($body)) {
                 $body = substr($body, $p + 4);
             }
         }
     }
     /*
     $body_without_header = '';
     $p2 = strpos( $buffer, "<?xml" ); 	// 第一次出现XML标记的位置
     if( $p2 > 1 )
     {
     	if( $p2-1 < strlen($buffer) )
     	{
     		$body_without_header = substr( $buffer,$p2-1 );
     	}
     }
     */
     try {
         if ($this->_header['Accept-Encoding'] == 'gzip,deflate') {
             $body = @gzdecode($body);
             if (!$body) {
                 trigger_error('返回体解析错误', E_USER_WARNING);
             }
         }
         if ($this->_header['Transfer-Encoding'] == 'chunked') {
             $body = @http_chunked_decode($body);
         }
     } catch (Exception $e) {
         trigger_error($e);
     }
     return $body;
 }
开发者ID:lz1988,项目名称:stourwebcms,代码行数:48,代码来源:MyHttp.class.php


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