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