summaryrefslogtreecommitdiff
path: root/plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2009-12-04 18:44:26 -0500
committerCraig Andrews <candrews@integralblue.com>2009-12-04 18:44:26 -0500
commitaab7344002fd390e5b62a3eb82f3a418fd294617 (patch)
treeb214e7d4b3e9f0ca9818fea9e3d9efa0249c00c6 /plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php
parent1fd7e5e3794621993b01a5833faa8b6fa26c3847 (diff)
parent01b089d9be046db1253cb3bb90e8635b50fddd84 (diff)
Merge branch 'minify' into 0.9.x
Diffstat (limited to 'plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php')
-rw-r--r--plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php b/plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php
new file mode 100644
index 000000000..9b66f2493
--- /dev/null
+++ b/plugins/Minify/extlib/minify/min_unit_tests/HTTP_ConditionalGet/2.php
@@ -0,0 +1,44 @@
+<?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;
+
+$cg = new HTTP_ConditionalGet(array(
+ 'lastModifiedTime' => $lastModified
+));
+if ($cg->cacheIsValid) {
+ $cg->sendHeaders();
+ // we're done
+ exit();
+}
+
+// generate content
+$title = 'Last-Modified is known : add Content-Length';
+$explain = '
+<p>Here, like <a href="./">the first example</a>, we know the Last-Modified time,
+but we also want to set the Content-Length to increase cacheability and allow
+HTTP persistent connections. Instead of sending headers immediately, we first
+generate our content, then use <code>setContentLength(strlen($content))</code>
+to add the header. Then finally call <code>sendHeaders()</code> and send the
+content.</p>
+<p><strong>Note:</strong> This is not required if your PHP config buffers all
+output and your script doesn\'t do any incremental flushing of the output
+buffer. PHP will generally set Content-Length for you if it can.</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->setContentLength(strlen($content));
+$cg->sendHeaders();
+send_slowly($content);
+