本文整理汇总了PHP中wfClientAcceptsGzip函数的典型用法代码示例。如果您正苦于以下问题:PHP wfClientAcceptsGzip函数的具体用法?PHP wfClientAcceptsGzip怎么用?PHP wfClientAcceptsGzip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfClientAcceptsGzip函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: wfGzipHandler
/**
* Handler that compresses data with gzip if allowed by the Accept header.
* Unlike ob_gzhandler, it works for HEAD requests too.
*/
function wfGzipHandler($s)
{
if (!function_exists('gzencode') || headers_sent()) {
return $s;
}
$ext = wfRequestExtension();
if ($ext == '.gz' || $ext == '.tgz') {
// Don't do gzip compression if the URL path ends in .gz or .tgz
// This confuses Safari and triggers a download of the page,
// even though it's pretty clearly labeled as viewable HTML.
// Bad Safari! Bad!
return $s;
}
if (wfClientAcceptsGzip()) {
header('Content-Encoding: gzip');
$s = gzencode($s, 6);
}
// Set vary header if it hasn't been set already
$headers = headers_list();
$foundVary = false;
foreach ($headers as $header) {
if (substr($header, 0, 5) == 'Vary:') {
$foundVary = true;
break;
}
}
if (!$foundVary) {
header('Vary: Accept-Encoding');
global $wgUseXVO;
if ($wgUseXVO) {
header('X-Vary-Options: Accept-Encoding;list-contains=gzip');
}
}
return $s;
}
开发者ID:rocLv,项目名称:conference,代码行数:39,代码来源:OutputHandler.php
示例2: saveToFileCache
public function saveToFileCache($text)
{
global $wgUseFileCache;
if (!$wgUseFileCache || strlen($text) < 512) {
// Disabled or empty/broken output (OOM and PHP errors)
return $text;
}
wfDebug(__METHOD__ . "()\n", false);
$this->checkCacheDirs();
$f = fopen($this->fileCacheName(), 'w');
if ($f) {
$now = wfTimestampNow();
if ($this->useGzip()) {
$rawtext = str_replace('</html>', '<!-- Cached/compressed ' . $now . " -->\n</html>", $text);
$text = gzencode($rawtext);
} else {
$text = str_replace('</html>', '<!-- Cached ' . $now . " -->\n</html>", $text);
}
fwrite($f, $text);
fclose($f);
if ($this->useGzip()) {
if (wfClientAcceptsGzip()) {
header('Content-Encoding: gzip');
return $text;
} else {
return $rawtext;
}
} else {
return $text;
}
}
return $text;
}
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:33,代码来源:HTMLFileCache.php
示例3: saveToFileCache
/**
* Save this cache object with the given text.
* Use this as an ob_start() handler.
* @param $text string
* @return bool Whether $wgUseFileCache is enabled
*/
public function saveToFileCache($text)
{
global $wgUseFileCache;
if (!$wgUseFileCache || strlen($text) < 512) {
// Disabled or empty/broken output (OOM and PHP errors)
return $text;
}
wfDebug(__METHOD__ . "()\n", 'log');
$now = wfTimestampNow();
if ($this->useGzip()) {
$text = str_replace('</html>', '<!-- Cached/compressed ' . $now . " -->\n</html>", $text);
} else {
$text = str_replace('</html>', '<!-- Cached ' . $now . " -->\n</html>", $text);
}
// Store text to FS...
$compressed = $this->saveText($text);
if ($compressed === false) {
return $text;
// error
}
// gzip output to buffer as needed and set headers...
if ($this->useGzip()) {
// @todo Ugly wfClientAcceptsGzip() function - use context!
if (wfClientAcceptsGzip()) {
header('Content-Encoding: gzip');
return $compressed;
} else {
return $text;
}
} else {
return $text;
}
}
开发者ID:Tarendai,项目名称:spring-website,代码行数:39,代码来源:HTMLFileCache.php
示例4: testClientAcceptsGzipTest
/**
* @covers ::wfClientAcceptsGzip
*/
public function testClientAcceptsGzipTest()
{
$settings = array('gzip' => true, 'bzip' => false, '*' => false, 'compress, gzip' => true, 'gzip;q=1.0' => true, 'foozip' => false, 'foo*zip' => false, 'gzip;q=abcde' => true, 'gzip;q=12345678.9' => true, ' gzip' => true);
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
}
foreach ($settings as $encoding => $expect) {
$_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
$this->assertEquals($expect, wfClientAcceptsGzip(true), "'{$encoding}' => " . wfBoolToStr($expect));
}
if (isset($old_server_setting)) {
$_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
}
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:17,代码来源:GlobalTest.php
示例5: wfGzipHandler
/**
* Handler that compresses data with gzip if allowed by the Accept header.
* Unlike ob_gzhandler, it works for HEAD requests too.
*
* @param string $s
*
* @return string
*/
function wfGzipHandler($s)
{
if (!function_exists('gzencode')) {
wfDebug(__FUNCTION__ . "() skipping compression (gzencode unavailable)\n");
return $s;
}
if (headers_sent()) {
wfDebug(__FUNCTION__ . "() skipping compression (headers already sent)\n");
return $s;
}
$ext = wfRequestExtension();
if ($ext == '.gz' || $ext == '.tgz') {
// Don't do gzip compression if the URL path ends in .gz or .tgz
// This confuses Safari and triggers a download of the page,
// even though it's pretty clearly labeled as viewable HTML.
// Bad Safari! Bad!
return $s;
}
if (wfClientAcceptsGzip()) {
wfDebug(__FUNCTION__ . "() is compressing output\n");
header('Content-Encoding: gzip');
$s = gzencode($s, 6);
}
// Set vary header if it hasn't been set already
$headers = headers_list();
$foundVary = false;
foreach ($headers as $header) {
$headerName = strtolower(substr($header, 0, 5));
if ($headerName == 'vary:') {
$foundVary = true;
break;
}
}
if (!$foundVary) {
header('Vary: Accept-Encoding');
global $wgUseKeyHeader;
if ($wgUseKeyHeader) {
header('Key: Accept-Encoding;match=gzip');
}
}
return $s;
}
开发者ID:foxlog,项目名称:wiki,代码行数:50,代码来源:OutputHandler.php
示例6: saveToFileCache
function saveToFileCache($origtext)
{
$text = $origtext;
if (strcmp($text, '') == 0) {
return '';
}
wfDebug(" saveToFileCache()\n", false);
$this->checkCacheDirs();
$f = fopen($this->fileCacheName(), 'w');
if ($f) {
$now = wfTimestampNow();
if ($this->useGzip()) {
$rawtext = str_replace('</html>', '<!-- Cached/compressed ' . $now . " -->\n</html>", $text);
$text = gzencode($rawtext);
} else {
$text = str_replace('</html>', '<!-- Cached ' . $now . " -->\n</html>", $text);
}
fwrite($f, $text);
fclose($f);
if ($this->useGzip()) {
if (wfClientAcceptsGzip()) {
header('Content-Encoding: gzip');
return $text;
} else {
return $rawtext;
}
} else {
return $text;
}
}
return $text;
}
开发者ID:puring0815,项目名称:OpenKore,代码行数:32,代码来源:CacheManager.php
注:本文中的wfClientAcceptsGzip函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论