summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChen-Pang He <jdh8@ms63.hinet.net>2014-06-30 15:50:20 +0800
committerczaks <marcin@6irc.net>2014-07-06 01:12:12 +0200
commit97069ea490b52181da8a434ff1a3e8603ac04adf (patch)
tree091ce2acc5abbd97da9c18e40aa7e631e5a5fa59
parentf4fd8162024b8f81c22077d30dd98a5af2ab51fd (diff)
Introduce $config['gzip_static']
-rw-r--r--inc/functions.php24
1 files changed, 23 insertions, 1 deletions
diff --git a/inc/functions.php b/inc/functions.php
index efc0594b..6854d8b7 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -1,7 +1,7 @@
<?php
/*
- * Copyright (c) 2010-2013 Tinyboard Development Group
+ * Copyright (c) 2010-2014 Tinyboard Development Group
*/
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
@@ -546,6 +546,28 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
if (!fclose($fp))
error('Unable to close file: ' . $path);
+ /**
+ * Create gzipped file.
+ *
+ * When writing into a file foo.bar and the size is larger or equal to 1
+ * KiB, this also produces the gzipped version foo.bar.gz
+ *
+ * This is useful with nginx with gzip_static on.
+ */
+ if ($config['gzip_static']) {
+ $gzpath = "$path.gz";
+
+ if ($bytes & ~0x3ff) { // if ($bytes >= 1024)
+ if (file_put_contents($gzpath, gzencode($data), $simple ? 0 : LOCK_EX) === false)
+ error("Unable to write to file: $gzpath");
+ if (!touch($gzpath, filemtime($path), fileatime($path)))
+ error("Unable to touch file: $gzpath");
+ }
+ else {
+ @unlink($gzpath);
+ }
+ }
+
if (!$skip_purge && isset($config['purge'])) {
// Purge cache
if (basename($path) == $config['file_index']) {