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


PHP HTTP_ConditionalGet::setContentLength方法代码示例

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


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

示例1: realpath

<?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


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