]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php
Added minify plugin
[quix0rs-gnu-social.git] / plugins / Minify / extlib / minify / min_unit_tests / HTTP_ConditionalGet / 2.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 $cg = new HTTP_ConditionalGet(array(
11     'lastModifiedTime' => $lastModified
12 ));
13 if ($cg->cacheIsValid) {
14     $cg->sendHeaders();
15     // we're done
16     exit();
17 }
18
19 // generate content
20 $title = 'Last-Modified is known : add Content-Length';
21 $explain = '
22 <p>Here, like <a href="./">the first example</a>, we know the Last-Modified time,
23 but we also want to set the Content-Length to increase cacheability and allow
24 HTTP persistent connections. Instead of sending headers immediately, we first
25 generate our content, then use <code>setContentLength(strlen($content))</code>
26 to add the header. Then finally call <code>sendHeaders()</code> and send the
27 content.</p>
28 <p><strong>Note:</strong> This is not required if your PHP config buffers all
29 output and your script doesn\'t do any incremental flushing of the output
30 buffer. PHP will generally set Content-Length for you if it can.</p>
31 <p>This script emulates a document that changes every ' .$every. ' seconds.
32 <br>This is version: ' . date('r', $lastModified) . '</p>
33 ';
34
35 require '_include.php';
36 $content = get_content(array(
37     'title' => $title
38     ,'explain' => $explain
39 ));
40
41 $cg->setContentLength(strlen($content));
42 $cg->sendHeaders();
43 send_slowly($content);
44