PHP 클래스 HTTP_ConditionalGet, minify

E.g. Content from DB with update time: list($updateTime, $content) = getDbUpdateAndContent(); $cg = new HTTP_ConditionalGet(array( 'lastModifiedTime' => $updateTime ,'isPublic' => true )); $cg->sendHeaders(); if ($cg->cacheIsValid) { exit(); } echo $content; E.g. Shortcut for the above HTTP_ConditionalGet::check($updateTime, true); // exits if client has cache echo $content; E.g. Content from DB with no update time: $content = getContentFromDB(); $cg = new HTTP_ConditionalGet(array( 'contentHash' => md5($content) )); $cg->sendHeaders(); if ($cg->cacheIsValid) { exit(); } echo $content; E.g. Static content with some static includes: before content $cg = new HTTP_ConditionalGet(array( 'lastUpdateTime' => max( filemtime(__FILE__) ,filemtime('/path/to/header.inc') ,filemtime('/path/to/footer.inc') ) )); $cg->sendHeaders(); if ($cg->cacheIsValid) { exit(); }
저자: Stephen Clay ([email protected])
파일 보기 프로젝트 열기: mrclay/minify 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$cacheIsValid boolean You'll want to check this after instantiating the object. If true, do not send content, just call sendHeaders() if you haven't already.

보호된 프로퍼티들

프로퍼티 타입 설명
$_etag
$_headers
$_lmTime
$_stripEtag

공개 메소드들

메소드 설명
__construct ( array $spec )
check ( integer $lastModifiedTime = null, boolean $isPublic = false, array $options = [] ) Exit if the client's cache is valid for this resource
getHeaders ( ) : array Get array of output headers to be sent
gmtDate ( integer $time ) : string Get a GMT formatted date for use in HTTP headers
sendHeaders ( ) : null Send headers
setContentLength ( integer $bytes ) : integer Set the Content-Length header in bytes

보호된 메소드들

메소드 설명
_isCacheValid ( ) : boolean Determine validity of client cache and queue 304 header if valid
_setEtag ( string $hash, string $scope )
_setLastModified ( integer $time )
normalizeEtag ( string $etag ) : string
resourceMatchedEtag ( ) : boolean
resourceNotModified ( ) : boolean

메소드 상세

__construct() 공개 메소드

public __construct ( array $spec )
$spec array options 'isPublic': (bool) if false, the Cache-Control header will contain "private", allowing only browser caching. (default false) 'lastModifiedTime': (int) if given, both ETag AND Last-Modified headers will be sent with content. This is recommended. 'encoding': (string) if set, the header "Vary: Accept-Encoding" will always be sent and a truncated version of the encoding will be appended to the ETag. E.g. "pub123456;gz". This will also trigger a more lenient checking of the client's If-None-Match header, as the encoding portion of the ETag will be stripped before comparison. 'contentHash': (string) if given, only the ETag header can be sent with content (only HTTP1.1 clients can conditionally GET). The given string should be short with no quote characters and always change when the resource changes (recommend md5()). This is not needed/used if lastModifiedTime is given. 'eTag': (string) if given, this will be used as the ETag header rather than values based on lastModifiedTime or contentHash. Also the encoding string will not be appended to the given value as described above. 'invalidate': (bool) if true, the client cache will be considered invalid without testing. Effectively this disables conditional GET. (default false) 'maxAge': (int) if given, this will set the Cache-Control max-age in seconds, and also set the Expires header to the equivalent GMT date. After the max-age period has passed, the browser will again send a conditional GET to revalidate its cache.

_isCacheValid() 보호된 메소드

Determine validity of client cache and queue 304 header if valid
protected _isCacheValid ( ) : boolean
리턴 boolean

_setEtag() 보호된 메소드

protected _setEtag ( string $hash, string $scope )
$hash string
$scope string

_setLastModified() 보호된 메소드

protected _setLastModified ( integer $time )
$time integer

check() 공개 정적인 메소드

This is a convenience method for common use of the class
public static check ( integer $lastModifiedTime = null, boolean $isPublic = false, array $options = [] )
$lastModifiedTime integer if given, both ETag AND Last-Modified headers will be sent with content. This is recommended.
$isPublic boolean (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.
$options array (default empty) additional options for constructor

getHeaders() 공개 메소드

In the case of 304 responses, this array will only contain the response code header: array('_responseCode' => 'HTTP/1.0 304 Not Modified') Otherwise something like: array( 'Cache-Control' => 'max-age=0, public' ,'ETag' => '"foobar"' )
public getHeaders ( ) : array
리턴 array

gmtDate() 공개 정적인 메소드

header('Expires: ' . HTTP_ConditionalGet::gmtdate($time));
public static gmtDate ( integer $time ) : string
$time integer unix timestamp
리턴 string

normalizeEtag() 보호된 메소드

protected normalizeEtag ( string $etag ) : string
$etag string
리턴 string

resourceMatchedEtag() 보호된 메소드

protected resourceMatchedEtag ( ) : boolean
리턴 boolean

resourceNotModified() 보호된 메소드

protected resourceNotModified ( ) : boolean
리턴 boolean

sendHeaders() 공개 메소드

Send headers
또한 보기: getHeaders() Note this doesn't "clear" the headers. Calling sendHeaders() will call header() again (but probably have not effect) and getHeaders() will still return the headers.
public sendHeaders ( ) : null
리턴 null

setContentLength() 공개 메소드

With most PHP configs, as long as you don't flush() output, this method is not needed and PHP will buffer all output and set Content-Length for you. Otherwise you'll want to call this to let the client know up front.
public setContentLength ( integer $bytes ) : integer
$bytes integer
리턴 integer copy of input $bytes

프로퍼티 상세

$_etag 보호되어 있는 프로퍼티

protected $_etag

$_headers 보호되어 있는 프로퍼티

protected $_headers

$_lmTime 보호되어 있는 프로퍼티

protected $_lmTime

$_stripEtag 보호되어 있는 프로퍼티

protected $_stripEtag

$cacheIsValid 공개적으로 프로퍼티

You'll want to check this after instantiating the object. If true, do not send content, just call sendHeaders() if you haven't already.
public bool $cacheIsValid
리턴 boolean