forked from GithubBackups/vichan
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3879e713a5 | ||
|
aeba30e4e1 | ||
|
c0b7d97ec1 | ||
|
ac4c2e0370 | ||
|
d918fddea1 | ||
|
6456924537 | ||
|
3d5404d589 | ||
|
d5e11b8fd9 | ||
|
499e609ec7 | ||
|
303ed52812 | ||
|
b9e443a1e2 |
21
contrib/files_in_cache.404.php.example
Normal file
21
contrib/files_in_cache.404.php.example
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'inc/functions.php';
|
||||||
|
|
||||||
|
$base=substr(dirname(str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME'])), 1);
|
||||||
|
//echo "base[$base]<br>\n";
|
||||||
|
|
||||||
|
$path=trim($_SERVER['REQUEST_URI'], '/');
|
||||||
|
$path=str_replace($base.'/', '', $path);
|
||||||
|
if (file_exists($path) && !is_dir($path)) {
|
||||||
|
if (strpos($path, 'css')!==false) {
|
||||||
|
header('Content-type: text/css');
|
||||||
|
}
|
||||||
|
readfile($path);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (is_dir($path)) {
|
||||||
|
$path.='/index.html';
|
||||||
|
}
|
||||||
|
$key='vichan_filecache_'.$path;
|
||||||
|
echo Cache::get($key);
|
||||||
|
?>
|
9
inc/cache.php
Normal file → Executable file
9
inc/cache.php
Normal file → Executable file
@ -90,7 +90,14 @@ class Cache {
|
|||||||
case 'redis':
|
case 'redis':
|
||||||
if (!self::$cache)
|
if (!self::$cache)
|
||||||
self::init();
|
self::init();
|
||||||
self::$cache->setex($key, $expires, json_encode($value));
|
|
||||||
|
if ($expires === FALSE) {
|
||||||
|
self::$cache->set($key, json_encode($value));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self::$cache->setex($key, $expires, json_encode($value));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'apc':
|
case 'apc':
|
||||||
apc_store($key, $value, $expires);
|
apc_store($key, $value, $expires);
|
||||||
|
@ -1196,6 +1196,18 @@
|
|||||||
// Try not to build pages when we shouldn't have to.
|
// Try not to build pages when we shouldn't have to.
|
||||||
$config['try_smarter'] = true;
|
$config['try_smarter'] = true;
|
||||||
|
|
||||||
|
// A reduced disk-IO option that does not write the HTML or JSON files to disk. It writes them to a
|
||||||
|
// cache which then can be quickly retrieved by a webserver without hitting the disk at all.
|
||||||
|
// See nginx's HttpRedis2Module module for a hint about a possible deployment.
|
||||||
|
|
||||||
|
// If you don't have HttpRedis2Module, i've included a 404.php that you can use with an htaccess like:
|
||||||
|
// RewriteEngine On
|
||||||
|
// RewriteRule ^[^/]+/$ %{REQUEST_URI}/../../404.php [NC,L]
|
||||||
|
// RewriteRule ^[^/]+/[^/]+$ %{REQUEST_URI}/../../404.php [NC,L]
|
||||||
|
// RewriteRule ^[^/]+/res/[^/]+$ %{REQUEST_URI}/../../404.php [NC,L]
|
||||||
|
// This example assumes your URL includes one directory level, i.e. http://localhost/vichan/
|
||||||
|
$config['files_in_cache'] = false;
|
||||||
|
|
||||||
// EXPERIMENTAL: Defer static HTML building to a moment, when a given file is actually accessed.
|
// EXPERIMENTAL: Defer static HTML building to a moment, when a given file is actually accessed.
|
||||||
// Warning: This option won't run out of the box. You need to tell your webserver, that a file
|
// Warning: This option won't run out of the box. You need to tell your webserver, that a file
|
||||||
// for serving 403 and 404 pages is /smart_build.php. Also, you need to turn off indexes.
|
// for serving 403 and 404 pages is /smart_build.php. Also, you need to turn off indexes.
|
||||||
|
6
inc/database.php
Normal file → Executable file
6
inc/database.php
Normal file → Executable file
@ -14,7 +14,8 @@ class PreparedQueryDebug {
|
|||||||
$query = preg_replace("/[\n\t]+/", ' ', $query);
|
$query = preg_replace("/[\n\t]+/", ' ', $query);
|
||||||
|
|
||||||
$this->query = $pdo->prepare($query);
|
$this->query = $pdo->prepare($query);
|
||||||
if ($config['debug'] && $config['debug_explain'] && preg_match('/^(SELECT|INSERT|UPDATE|DELETE) /i', $query))
|
//|INSERT|UPDATE|DELETE
|
||||||
|
if ($config['debug'] && $config['debug_explain'] && preg_match('/^(SELECT) /i', $query))
|
||||||
$this->explain_query = $pdo->prepare("EXPLAIN $query");
|
$this->explain_query = $pdo->prepare("EXPLAIN $query");
|
||||||
}
|
}
|
||||||
public function __call($function, $args) {
|
public function __call($function, $args) {
|
||||||
@ -127,7 +128,8 @@ function query($query) {
|
|||||||
sql_open();
|
sql_open();
|
||||||
|
|
||||||
if ($config['debug']) {
|
if ($config['debug']) {
|
||||||
if ($config['debug_explain'] && preg_match('/^(SELECT|INSERT|UPDATE|DELETE) /i', $query)) {
|
//|INSERT|UPDATE|DELETE
|
||||||
|
if ($config['debug_explain'] && preg_match('/^(SELECT) /i', $query)) {
|
||||||
$explain = $pdo->query("EXPLAIN $query") or error(db_error());
|
$explain = $pdo->query("EXPLAIN $query") or error(db_error());
|
||||||
}
|
}
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
@ -643,49 +643,63 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$fp = fopen($path, $simple ? 'w' : 'c'))
|
if ($config['files_in_cache']) {
|
||||||
error('Unable to open file for writing: ' . $path);
|
Cache::set('vichan_filecache_'.$path, $data);
|
||||||
|
if ($config['gzip_static']) {
|
||||||
// File locking
|
$bytes=strlen($data);
|
||||||
if (!$simple && !flock($fp, LOCK_EX)) {
|
if ($bytes & ~0x3ff) {
|
||||||
error('Unable to lock file: ' . $path);
|
Cache::set('vichan_filecache_'.$path.'.gz', gzencode($data));
|
||||||
}
|
} else {
|
||||||
|
Cache::delete('vichan_filecache_'.$path.'.gz');
|
||||||
// Truncate file
|
}
|
||||||
if (!$simple && !ftruncate($fp, 0))
|
|
||||||
error('Unable to truncate file: ' . $path);
|
|
||||||
|
|
||||||
// Write data
|
|
||||||
if (($bytes = fwrite($fp, $data)) === false)
|
|
||||||
error('Unable to write to file: ' . $path);
|
|
||||||
|
|
||||||
// Unlock
|
|
||||||
if (!$simple)
|
|
||||||
flock($fp, LOCK_UN);
|
|
||||||
|
|
||||||
// Close
|
|
||||||
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);
|
else {
|
||||||
|
if (!$fp = fopen($path, $simple ? 'w' : 'c'))
|
||||||
|
error('Unable to open file for writing: ' . $path);
|
||||||
|
|
||||||
|
// File locking
|
||||||
|
if (!$simple && !flock($fp, LOCK_EX)) {
|
||||||
|
error('Unable to lock file: ' . $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Truncate file
|
||||||
|
if (!$simple && !ftruncate($fp, 0))
|
||||||
|
error('Unable to truncate file: ' . $path);
|
||||||
|
|
||||||
|
// Write data
|
||||||
|
if (($bytes = fwrite($fp, $data)) === false)
|
||||||
|
error('Unable to write to file: ' . $path);
|
||||||
|
|
||||||
|
// Unlock
|
||||||
|
if (!$simple)
|
||||||
|
flock($fp, LOCK_UN);
|
||||||
|
|
||||||
|
// Close
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,6 +719,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($config['debug']) {
|
if ($config['debug']) {
|
||||||
|
$bytes=strlen($data);
|
||||||
$debug['write'][] = $path . ': ' . $bytes . ' bytes';
|
$debug['write'][] = $path . ': ' . $bytes . ' bytes';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,11 +735,15 @@ function file_unlink($path) {
|
|||||||
$debug['unlink'][] = $path;
|
$debug['unlink'][] = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Cache::delete('vichan_filecache_'.$path);
|
||||||
|
if ($config['gzip_static']) {
|
||||||
|
Cache::delete('vichan_filecache_'.$path.'.gz');
|
||||||
|
}
|
||||||
|
|
||||||
$ret = @unlink($path);
|
$ret = @unlink($path);
|
||||||
|
if ($config['gzip_static']) {
|
||||||
if ($config['gzip_static']) {
|
$gzpath = "$path.gz";
|
||||||
$gzpath = "$path.gz";
|
|
||||||
|
|
||||||
@unlink($gzpath);
|
@unlink($gzpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user