This commit is contained in:
czaks 2016-01-26 01:13:20 +01:00
commit d918fddea1
5 changed files with 206 additions and 112 deletions

21
404.php Normal file
View 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);
?>

20
README.md Normal file → Executable file
View File

@ -1,7 +1,23 @@
vichan - A lightweight and full featured PHP imageboard. modified vichan
======================================================== ========================================================
About OdiliTime Modifications
-----------------------
This is a reduced disk-IO version that does not write the HTML or JSON files to disk.
It writes them to a redis-backed memory store which then can be quickly retrieved by a webserver
without hitting the disk at all. See nginx's HttpRedis2Module module for more of what I mean.
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/
About vichan
------------ ------------
vichan is a free light-weight, fast, highly configurable and user-friendly vichan is a free light-weight, fast, highly configurable and user-friendly
imageboard software package. It is written in PHP and has few dependencies. imageboard software package. It is written in PHP and has few dependencies.

35
inc/cache.php Normal file → Executable file
View File

@ -111,6 +111,41 @@ class Cache {
if ($config['debug']) if ($config['debug'])
$debug['cached'][] = $key . ' (set)'; $debug['cached'][] = $key . ' (set)';
} }
public static function store($key, $value) {
global $config, $debug;
$key = $config['cache']['prefix'] . $key;
switch ($config['cache']['enabled']) {
case 'memcached':
if (!self::$cache)
self::init();
self::$cache->set($key, $value);
break;
case 'redis':
if (!self::$cache)
self::init();
self::$cache->set($key, json_encode($value));
break;
case 'apc':
apc_store($key, $value);
break;
case 'xcache':
xcache_set($key, $value);
break;
case 'fs':
$key = str_replace('/', '::', $key);
$key = str_replace("\0", '', $key);
file_put_contents('tmp/cache/'.$key, json_encode($value));
break;
case 'php':
self::$cache[$key] = $value;
break;
}
if ($config['debug'])
$debug['cached'][] = $key . ' (set)';
}
public static function delete($key) { public static function delete($key) {
global $config, $debug; global $config, $debug;

6
inc/database.php Normal file → Executable file
View 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);

View File

@ -630,6 +630,16 @@ function purge($uri) {
function file_write($path, $data, $simple = false, $skip_purge = false) { function file_write($path, $data, $simple = false, $skip_purge = false) {
global $config, $debug; global $config, $debug;
//echo "file_write($path, ", strlen($data), ", $simple, $skip_purge)<br>\n";
Cache::store('vichan_filecache_'.$path, $data, -1);
if ($config['gzip_static']) {
$bytes=strlen($data);
if ($bytes & ~0x3ff) {
Cache::store('vichan_filecache_'.$path.'.gz', gzencode($data), -1);
} else {
Cache::delete('vichan_filecache_'.$path.'.gz');
}
}
if (preg_match('/^remote:\/\/(.+)\:(.+)$/', $path, $m)) { if (preg_match('/^remote:\/\/(.+)\:(.+)$/', $path, $m)) {
if (isset($config['remote'][$m[1]])) { if (isset($config['remote'][$m[1]])) {
@ -643,6 +653,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
} }
} }
/*
if (!$fp = fopen($path, $simple ? 'w' : 'c')) if (!$fp = fopen($path, $simple ? 'w' : 'c'))
error('Unable to open file for writing: ' . $path); error('Unable to open file for writing: ' . $path);
@ -666,7 +677,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
// Close // Close
if (!fclose($fp)) if (!fclose($fp))
error('Unable to close file: ' . $path); error('Unable to close file: ' . $path);
*/
/** /**
* Create gzipped file. * Create gzipped file.
* *
@ -675,6 +686,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
* *
* This is useful with nginx with gzip_static on. * This is useful with nginx with gzip_static on.
*/ */
/*
if ($config['gzip_static']) { if ($config['gzip_static']) {
$gzpath = "$path.gz"; $gzpath = "$path.gz";
@ -688,6 +700,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
@unlink($gzpath); @unlink($gzpath);
} }
} }
*/
if (!$skip_purge && isset($config['purge'])) { if (!$skip_purge && isset($config['purge'])) {
// Purge cache // Purge cache
@ -705,6 +718,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';
} }
@ -713,6 +727,12 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
function file_unlink($path) { function file_unlink($path) {
global $config, $debug; global $config, $debug;
//echo "file_unlink($path)<br>\n";
if ($config['gzip_static']) {
Cache::delete('vichan_filecache_'.$path);
} else {
Cache::delete('vichan_filecache_'.$path.'.gz');
}
if ($config['debug']) { if ($config['debug']) {
if (!isset($debug['unlink'])) if (!isset($debug['unlink']))
@ -720,14 +740,14 @@ function file_unlink($path) {
$debug['unlink'][] = $path; $debug['unlink'][] = $path;
} }
$ret=true;
/*
$ret = @unlink($path); $ret = @unlink($path);
if ($config['gzip_static']) { if ($config['gzip_static']) {
$gzpath = "$path.gz"; $gzpath = "$path.gz";
@unlink($gzpath); @unlink($gzpath);
} }
*/
if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) { if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) {
// Purge cache // Purge cache
if (basename($path) == $config['file_index']) { if (basename($path) == $config['file_index']) {