• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP HTTP_ConditionalGet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_HTTP_ConditionalGet

function test_HTTP_ConditionalGet()
{
    global $thisDir;
    $lmTime = time() - 900;
    $gmtTime = gmdate('D, d M Y H:i:s \\G\\M\\T', $lmTime);
    $tests = array(array('desc' => 'client has valid If-Modified-Since', 'inm' => null, 'ims' => $gmtTime, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime}\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'client has valid If-Modified-Since with trailing semicolon', 'inm' => null, 'ims' => $gmtTime . ';', 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime}\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'client has valid ETag (non-encoded version)', 'inm' => "\"badEtagFoo\", \"pri{$lmTime}\"", 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime}\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'client has valid ETag (gzip version)', 'inm' => "\"badEtagFoo\", \"pri{$lmTime};gz\"", 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'no conditional get', 'inm' => null, 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', 'isValid' => false)), array('desc' => 'client has invalid ETag', 'inm' => '"pri' . ($lmTime - 300) . '"', 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', 'isValid' => false)), array('desc' => 'client has invalid If-Modified-Since', 'inm' => null, 'ims' => gmdate('D, d M Y H:i:s \\G\\M\\T', $lmTime - 300), 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', 'isValid' => false)));
    foreach ($tests as $test) {
        // setup env
        if (null === $test['inm']) {
            unset($_SERVER['HTTP_IF_NONE_MATCH']);
        } else {
            $_SERVER['HTTP_IF_NONE_MATCH'] = get_magic_quotes_gpc() ? addslashes($test['inm']) : $test['inm'];
        }
        if (null === $test['ims']) {
            unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
        } else {
            $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $test['ims'];
        }
        $exp = $test['exp'];
        $cg = new HTTP_ConditionalGet(array('lastModifiedTime' => $lmTime, 'encoding' => 'x-gzip'));
        $ret = $cg->getHeaders();
        $ret['isValid'] = $cg->cacheIsValid;
        $passed = assertTrue($exp == $ret, 'HTTP_ConditionalGet : ' . $test['desc']);
        if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
            echo "\n--- INM = {$test['inm']} / IMS = {$test['ims']}\n";
            echo "Expected = " . preg_replace('/\\s+/', ' ', var_export($exp, 1)) . "\n";
            echo "Returned = " . preg_replace('/\\s+/', ' ', var_export($ret, 1)) . "\n\n";
        }
    }
}
开发者ID:chaoyanjie,项目名称:HiBlog,代码行数:30,代码来源:test_HTTP_ConditionalGet.php


示例2: render

 public static function render($arrFilter)
 {
     $dtLastModified = 0;
     //*** Load sources from sources directory.
     if (is_dir($GLOBALS["_PATHS"]['css'])) {
         //*** Directory exists.
         foreach ($arrFilter as $strFilter) {
             $strFile = $GLOBALS["_PATHS"]['css'] . "{$strFilter}.css";
             $dtLastModified = self::getLastModified($strFile, $dtLastModified);
             //*** Auto check custom files.
             if (strpos($strFilter, "-custom") === false) {
                 $strFile = $GLOBALS["_PATHS"]['css'] . "{$strFilter}-custom.css";
                 $dtLastModified = self::getLastModified($strFile, $dtLastModified);
             }
         }
     }
     //*** Check if we can send a "Not Modified" header.
     \HTTP_ConditionalGet::check($dtLastModified, true, array("maxAge" => 1200000));
     //*** Modified. Get contents.
     $strOutput = self::minify($arrFilter);
     //*** Gzip the CSS.
     $objEncoder = new \HTTP_Encoder(array("content" => $strOutput, "type" => "text/css"));
     $objEncoder->encode();
     $objEncoder->sendAll();
 }
开发者ID:rvanbaalen,项目名称:bili,代码行数:25,代码来源:CSSIncluder.php


示例3: _checkClientCache

 private static function _checkClientCache()
 {
     require_once 'HTTP/ConditionalGet.php';
     $cgOptions = array('lastModifiedTime' => 0, 'isPublic' => true, 'encoding' => '', 'maxAge' => 1800);
     $cg = new HTTP_ConditionalGet($cgOptions);
     if (MINCO_CLIENT_CACHE && $cg->cacheIsValid) {
         // client's cache is valid
         $cg->sendHeaders();
         return true;
     } else {
         // client will need output
         self::$_headers = $cg->getHeaders();
         unset($cg);
     }
     return false;
 }
开发者ID:noxstyle,项目名称:c5_mainio_minco,代码行数:16,代码来源:minco_file_writer.php


示例4: render

 public static function render($arrFilter)
 {
     $dtLastModified = 0;
     //*** Load sources from sources directory.
     if (is_dir($GLOBALS["_PATHS"]['js'])) {
         //*** Directory exists.
         foreach ($arrFilter as $strFilter) {
             $strFile = $GLOBALS["_PATHS"]['js'] . $strFilter . ".js";
             if (is_file($strFile)) {
                 $lngLastModified = filemtime($strFile);
                 if (empty($dtLastModified) || $lngLastModified > $dtLastModified) {
                     $dtLastModified = $lngLastModified;
                 }
             }
         }
     }
     //*** Check if we can send a "Not Modified" header.
     \HTTP_ConditionalGet::check($dtLastModified, true, array("maxAge" => 1200000));
     //*** Modified. Get contents.
     $strOutput = self::minify($arrFilter);
     //*** Gzip the Javascript.
     $objEncoder = new \HTTP_Encoder(array("content" => $strOutput, "type" => "text/javascript"));
     $objEncoder->encode();
     $objEncoder->sendAll();
 }
开发者ID:rvanbaalen,项目名称:bili,代码行数:25,代码来源:JSIncluder.php


示例5: serve


//.........这里部分代码省略.........
     }
     self::$_controller = $controller;
     if (self::$_options['debug']) {
         self::_setupDebug($controller->sources);
         self::$_options['maxAge'] = 0;
     }
     // determine encoding
     if (self::$_options['encodeOutput']) {
         $sendVary = true;
         if (self::$_options['encodeMethod'] !== null) {
             // controller specifically requested this
             $contentEncoding = self::$_options['encodeMethod'];
         } else {
             // sniff request header
             require_once 'HTTP/Encoder.php';
             // depending on what the client accepts, $contentEncoding may be
             // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
             // getAcceptedEncoding(false, false) leaves out compress and deflate as options.
             list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
             $sendVary = !HTTP_Encoder::isBuggyIe();
         }
     } else {
         self::$_options['encodeMethod'] = '';
         // identity (no encoding)
     }
     // check client cache
     require_once 'HTTP/ConditionalGet.php';
     $cgOptions = array('lastModifiedTime' => self::$_options['lastModifiedTime'], 'isPublic' => self::$_options['isPublic'], 'encoding' => self::$_options['encodeMethod']);
     if (self::$_options['maxAge'] > 0) {
         $cgOptions['maxAge'] = self::$_options['maxAge'];
     } elseif (self::$_options['debug']) {
         $cgOptions['invalidate'] = true;
     }
     $cg = new HTTP_ConditionalGet($cgOptions);
     if ($cg->cacheIsValid) {
         // client's cache is valid
         if (!self::$_options['quiet']) {
             $cg->sendHeaders();
             return;
         } else {
             return array('success' => true, 'statusCode' => 304, 'content' => '', 'headers' => $cg->getHeaders());
         }
     } else {
         // client will need output
         $headers = $cg->getHeaders();
         unset($cg);
     }
     if (self::$_options['contentType'] === self::TYPE_CSS && self::$_options['rewriteCssUris']) {
         foreach ($controller->sources as $key => $source) {
             if ($source->filepath && !isset($source->minifyOptions['currentDir']) && !isset($source->minifyOptions['prependRelativePath'])) {
                 $source->minifyOptions['currentDir'] = dirname($source->filepath);
             }
         }
     }
     // check server cache
     if (null !== self::$_cache && !self::$_options['debug']) {
         // using cache
         // the goal is to use only the cache methods to sniff the length and
         // output the content, as they do not require ever loading the file into
         // memory.
         $cacheId = self::_getCacheId();
         $fullCacheId = self::$_options['encodeMethod'] ? $cacheId . '.gz' : $cacheId;
         // check cache for valid entry
         $cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
         if ($cacheIsReady) {
             $cacheContentLength = self::$_cache->getSize($fullCacheId);
开发者ID:mover5,项目名称:imobackup,代码行数:67,代码来源:Minify.php


示例6: check

 /**
  * Exit if the client's cache is valid for this resource
  *
  * This is a convenience method for common use of the class
  *
  * @param int $lastModifiedTime if given, both ETag AND Last-Modified headers
  * will be sent with content. This is recommended.
  *
  * @param bool $isPublic (default false) if true, the Cache-Control header 
  * will contain "public", allowing proxies to cache the content. Otherwise 
  * "private" will be sent, allowing only browser caching.
  *
  * @param array $options (default empty) additional options for constructor
  */
 public static function check($lastModifiedTime = null, $isPublic = false, $options = array())
 {
     if (null !== $lastModifiedTime) {
         $options['lastModifiedTime'] = (int) $lastModifiedTime;
     }
     $options['isPublic'] = (bool) $isPublic;
     $cg = new HTTP_ConditionalGet($options);
     $cg->sendHeaders();
     if ($cg->cacheIsValid) {
         exit;
     }
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:26,代码来源:ConditionalGet.php


示例7: set_include_path

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib'));
require 'HTTP/ConditionalGet.php';
// generate content first (not ideal)
// emulate regularly updating document
$every = 20;
$lastModified = round(time() / $every) * $every - $every;
$title = 'Last-Modified is unknown : use hash of content for ETag';
$explain = '
<p>When Last-Modified is unknown, you can still use ETags, but you need a short
string that is unique for that content. In the worst case, you have to generate
all the content first, <em>then</em> instantiate HTTP_ConditionalGet, setting
the array key <code>contentHash</code> to the output of a hash function of the
content. Since we have the full content, we might as well also use
<code>setContentLength(strlen($content))</code> in the case where we need to
send it.</p>
<p>This script emulates a document that changes every ' . $every . ' seconds.
<br>This is version: ' . date('r', $lastModified) . '</p>
';
require '_include.php';
$content = get_content(array('title' => $title, 'explain' => $explain));
$cg = new HTTP_ConditionalGet(array('contentHash' => substr(md5($content), 7)));
if ($cg->cacheIsValid) {
    $cg->sendHeaders();
    // we're done
    exit;
}
$cg->setContentLength(strlen($content));
$cg->sendHeaders();
send_slowly($content);
开发者ID:zepluf,项目名称:plugin-ricjloader,代码行数:31,代码来源:3.php


示例8: round

<?php

require '../../config.php';
require 'HTTP/ConditionalGet.php';
// emulate regularly updating document
$every = 20;
$lastModified = round(time() / $every) * $every - $every;
$cg = new HTTP_ConditionalGet(array('lastModifiedTime' => $lastModified));
$cg->sendHeaders();
if ($cg->cacheIsValid) {
    // we're done
    exit;
}
$title = 'Last-Modified is known : simple usage';
$explain = '
<p>If your content has not changed since a certain timestamp, set this via the
the <code>lastModifiedTime</code> array key when instantiating HTTP_ConditionalGet.
You can immediately call the method <code>sendHeaders()</code> to set the
Last-Modified, ETag, and Cache-Control headers. The, if <code>cacheIsValid</code>
property is false, you echo the content.</p>
<p>This script emulates a document that changes every ' . $every . ' seconds.
<br>This is version: ' . date('r', $lastModified) . '</p>
';
require '_include.php';
echo send_slowly(get_content(array('title' => $title, 'explain' => $explain)));
开发者ID:bigbash,项目名称:longurl,代码行数:25,代码来源:index.php


示例9: _echo_javascript

 /**
  * Echoes the Javascript if not cached.
  *
  * Echoes the javascript with the correct content.
  * Since the content is dinamic, i use the hash function.
  *
  * @param string $javascript
  *
  * @return void
  */
 private function _echo_javascript($javascript)
 {
     $conditional_get = new HTTP_ConditionalGet(array('contentHash' => md5($javascript)));
     $conditional_get->sendHeaders();
     if (!$conditional_get->cacheIsValid) {
         $http_encoder = $this->_registry->get('http.encoder', array('content' => $javascript, 'type' => 'text/javascript'));
         $compression_level = null;
         if ($this->_registry->get('model.settings')->get('disable_gzip_compression')) {
             // set the compression level to 0 to disable it.
             $compression_level = 0;
         }
         $http_encoder->encode($compression_level);
         $http_encoder->sendAll();
     }
     Ai1ec_Http_Response_Helper::stop(0);
 }
开发者ID:piratas,项目名称:piratas-site,代码行数:26,代码来源:javascript.php


示例10: serve


//.........这里部分代码省略.........
         } else {
             list(, $statusCode) = explode(' ', self::$_options['badRequestHeader']);
             return array('success' => false, 'statusCode' => (int) $statusCode, 'content' => '', 'headers' => array());
         }
     }
     self::$_controller = $controller;
     if (self::$_options['debug']) {
         self::_setupDebug($controller->sources);
         self::$_options['maxAge'] = 0;
     }
     // determine encoding
     if (self::$_options['encodeOutput']) {
         if (self::$_options['encodeMethod'] !== null) {
             // controller specifically requested this
             $contentEncoding = self::$_options['encodeMethod'];
         } else {
             // sniff request header
             require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
             // depending on what the client accepts, $contentEncoding may be
             // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
             // getAcceptedEncoding(false, false) leaves out compress and deflate as options.
             list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(self::$_options['encodeOutput']);
         }
     } else {
         self::$_options['encodeMethod'] = '';
         // identity (no encoding)
     }
     // check client cache
     require_once W3TC_LIB_MINIFY_DIR . '/HTTP/ConditionalGet.php';
     $cgOptions = array('cacheHeaders' => self::$_options['cacheHeaders'], 'lastModifiedTime' => self::$_options['lastModifiedTime'], 'isPublic' => self::$_options['isPublic'], 'encoding' => self::$_options['encodeMethod']);
     if (self::$_options['maxAge'] > 0) {
         $cgOptions['maxAge'] = self::$_options['maxAge'];
     }
     $cg = new HTTP_ConditionalGet($cgOptions);
     if ($cg->cacheIsValid) {
         // client's cache is valid
         if (!self::$_options['quiet']) {
             $cg->sendHeaders();
             return;
         } else {
             return array('success' => true, 'statusCode' => 304, 'content' => '', 'headers' => $cg->getHeaders());
         }
     } else {
         // client will need output
         $headers = $cg->getHeaders();
         unset($cg);
     }
     if (self::$_options['contentType'] === self::TYPE_CSS) {
         reset($controller->sources);
         while (list($key, $source) = each($controller->sources)) {
             if (self::$_options['rewriteCssUris'] && $source->filepath && !isset($source->minifyOptions['currentDir']) && !isset($source->minifyOptions['prependRelativePath'])) {
                 $source->minifyOptions['currentDir'] = dirname($source->filepath);
             }
             $source->minifyOptions['processCssImports'] = self::$_options['processCssImports'];
         }
     }
     // check server cache
     if (null !== self::$_cache) {
         // using cache
         // the goal is to use only the cache methods to sniff the length and
         // output the content, as they do not require ever loading the file into
         // memory.
         $cacheId = self::_getCacheId();
         $fullCacheId = self::$_options['encodeMethod'] ? $cacheId . '.' . self::$_options['encodeMethod'] : $cacheId;
         // check cache for valid entry
         $cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
开发者ID:nuevomediagroup,项目名称:nmg-code,代码行数:67,代码来源:Minify.php


示例11: serve


//.........这里部分代码省略.........
             return array('success' => false, 'statusCode' => (int) $statusCode, 'content' => '', 'headers' => array());
         }
     }
     $this->controller = $controller;
     if ($this->options['debug']) {
         $this->setupDebug();
         $this->options['maxAge'] = 0;
     }
     // determine encoding
     if ($this->options['encodeOutput']) {
         $sendVary = true;
         if ($this->options['encodeMethod'] !== null) {
             // controller specifically requested this
             $contentEncoding = $this->options['encodeMethod'];
         } else {
             // sniff request header
             // depending on what the client accepts, $contentEncoding may be
             // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
             // getAcceptedEncoding(false, false) leaves out compress and deflate as options.
             list($this->options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
             $sendVary = !HTTP_Encoder::isBuggyIe();
         }
     } else {
         $this->options['encodeMethod'] = '';
         // identity (no encoding)
     }
     // check client cache
     $cgOptions = array('lastModifiedTime' => $this->options['lastModifiedTime'], 'isPublic' => $this->options['isPublic'], 'encoding' => $this->options['encodeMethod']);
     if ($this->options['maxAge'] > 0) {
         $cgOptions['maxAge'] = $this->options['maxAge'];
     } elseif ($this->options['debug']) {
         $cgOptions['invalidate'] = true;
     }
     $cg = new HTTP_ConditionalGet($cgOptions);
     if ($cg->cacheIsValid) {
         // client's cache is valid
         if (!$this->options['quiet']) {
             $cg->sendHeaders();
             return;
         } else {
             return array('success' => true, 'statusCode' => 304, 'content' => '', 'headers' => $cg->getHeaders());
         }
     } else {
         // client will need output
         $headers = $cg->getHeaders();
         unset($cg);
     }
     if ($this->options['contentType'] === self::TYPE_CSS && $this->options['rewriteCssUris']) {
         $this->setupUriRewrites();
     }
     if ($this->options['concatOnly']) {
         $this->options['minifiers'][self::TYPE_JS] = false;
         foreach ($this->sources as $key => $source) {
             if ($this->options['contentType'] === self::TYPE_JS) {
                 $source->setMinifier("");
             } elseif ($this->options['contentType'] === self::TYPE_CSS) {
                 $source->setMinifier(array('Minify_CSSmin', 'minify'));
                 $sourceOpts = $source->getMinifierOptions();
                 $sourceOpts['compress'] = false;
                 $source->setMinifierOptions($sourceOpts);
             }
         }
     }
     // check server cache
     if (!$this->options['debug']) {
         // using cache
开发者ID:chaoyanjie,项目名称:HiBlog,代码行数:67,代码来源:Minify.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP HTTP_Encoder类代码示例发布时间:2022-05-23
下一篇:
PHP HTTPRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap