blob: 4b77d2084bdd6cc64d3f6da879493f239e95f5a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib'));
require 'HTTP/ConditionalGet.php';
// emulate regularly updating document
$every = 20;
$lastModified = round(time()/$every)*$every - $every;
require 'HTTP/Encoder.php';
list($enc,) = HTTP_Encoder::getAcceptedEncoding();
$cg = new HTTP_ConditionalGet(array(
'lastModifiedTime' => $lastModified
,'encoding' => $enc
));
$cg->sendHeaders();
if ($cg->cacheIsValid) {
// we're done
exit();
}
// output encoded content
$title = 'ConditionalGet + Encoder';
$explain = '
<p>Using ConditionalGet and Encoder is straightforward. First impliment the
ConditionalGet, then if the cache is not valid, encode and send 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';
$content = get_content(array(
'title' => $title
,'explain' => $explain
));
$he = new HTTP_Encoder(array(
'content' => get_content(array(
'title' => $title
,'explain' => $explain
))
));
$he->encode();
// usually you would just $he->sendAll(), but here we want to emulate slow
// connection
$he->sendHeaders();
send_slowly($he->getContent());
|