diff --git a/404.php b/404.php new file mode 100644 index 00000000..bacac61f --- /dev/null +++ b/404.php @@ -0,0 +1,21 @@ +\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); +?> diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 6e153ab7..c3b18170 --- a/README.md +++ b/README.md @@ -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 imageboard software package. It is written in PHP and has few dependencies. @@ -17,7 +33,7 @@ Requirements 1. PHP >= 5.4 (we still try to keep compatibility with php 5.3 as much as possible) PHP 7.0 is explicitly supported. 2. MySQL/MariaDB server -3. [mbstring](http://www.php.net/manual/en/mbstring.installation.php) +3. [mbstring](http://www.php.net/manual/en/mbstring.installation.php) 4. [PHP GD](http://www.php.net/manual/en/intro.image.php) 5. [PHP PDO](http://www.php.net/manual/en/intro.pdo.php) @@ -47,7 +63,7 @@ Installation development version with: git clone git://github.com/vichan-devel/vichan.git - + 2. Navigate to ```install.php``` in your web browser and follow the prompts. 3. vichan should now be installed. Log in to ```mod.php``` with the @@ -84,7 +100,7 @@ find support from a variety of sources: ### Tinyboard support vichan is based on a Tinyboard, so both engines have very much in common. These -links may be helpful for you as well: +links may be helpful for you as well: * Tinyboard documentation can be found [here](https://web.archive.org/web/20121016074303/http://tinyboard.org/docs/?p=Main_Page). diff --git a/inc/cache.php b/inc/cache.php old mode 100644 new mode 100755 index 852aefa2..c5865fa9 --- a/inc/cache.php +++ b/inc/cache.php @@ -10,7 +10,7 @@ class Cache { private static $cache; public static function init() { global $config; - + switch ($config['cache']['enabled']) { case 'memcached': self::$cache = new Memcached(); @@ -31,9 +31,9 @@ class Cache { } public static function get($key) { global $config, $debug; - + $key = $config['cache']['prefix'] . $key; - + $data = false; switch ($config['cache']['enabled']) { case 'memcached': @@ -67,20 +67,20 @@ class Cache { $data = json_decode(self::$cache->get($key), true); break; } - + if ($config['debug']) $debug['cached'][] = $key . ($data === false ? ' (miss)' : ' (hit)'); - + return $data; } public static function set($key, $value, $expires = false) { global $config, $debug; - + $key = $config['cache']['prefix'] . $key; - + if (!$expires) $expires = $config['cache']['timeout']; - + switch ($config['cache']['enabled']) { case 'memcached': if (!self::$cache) @@ -107,15 +107,50 @@ class Cache { self::$cache[$key] = $value; break; } - + + if ($config['debug']) + $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) { global $config, $debug; - + $key = $config['cache']['prefix'] . $key; - + switch ($config['cache']['enabled']) { case 'memcached': case 'redis': @@ -138,13 +173,13 @@ class Cache { unset(self::$cache[$key]); break; } - + if ($config['debug']) $debug['cached'][] = $key . ' (deleted)'; } public static function flush() { global $config; - + switch ($config['cache']['enabled']) { case 'memcached': if (!self::$cache) @@ -166,7 +201,7 @@ class Cache { self::init(); return self::$cache->flushDB(); } - + return false; } } diff --git a/inc/database.php b/inc/database.php old mode 100644 new mode 100755 index 84a050f2..5938fe2d --- a/inc/database.php +++ b/inc/database.php @@ -8,30 +8,31 @@ defined('TINYBOARD') or exit; class PreparedQueryDebug { protected $query, $explain_query = false; - + public function __construct($query) { global $pdo, $config; $query = preg_replace("/[\n\t]+/", ' ', $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"); } public function __call($function, $args) { global $config, $debug; - + if ($config['debug'] && $function == 'execute') { if ($this->explain_query) { $this->explain_query->execute() or error(db_error($this->explain_query)); } $start = microtime(true); } - + if ($this->explain_query && $function == 'bindValue') call_user_func_array(array($this->explain_query, $function), $args); - + $return = call_user_func_array(array($this->query, $function), $args); - + if ($config['debug'] && $function == 'execute') { $time = microtime(true) - $start; $debug['sql'][] = array( @@ -42,7 +43,7 @@ class PreparedQueryDebug { ); $debug['time']['db_queries'] += $time; } - + return $return; } } @@ -51,16 +52,16 @@ function sql_open() { global $pdo, $config, $debug; if ($pdo) return true; - - + + if ($config['debug']) $start = microtime(true); - + if (isset($config['db']['server'][0]) && $config['db']['server'][0] == ':') $unix_socket = substr($config['db']['server'], 1); else $unix_socket = false; - + $dsn = $config['db']['type'] . ':' . ($unix_socket ? 'unix_socket=' . $unix_socket : 'host=' . $config['db']['server']) . ';dbname=' . $config['db']['database']; @@ -74,10 +75,10 @@ function sql_open() { if ($config['db']['persistent']) $options[PDO::ATTR_PERSISTENT] = true; $pdo = new PDO($dsn, $config['db']['user'], $config['db']['password'], $options); - + if ($config['debug']) $debug['time']['db_connect'] = '~' . round((microtime(true) - $start) * 1000, 2) . 'ms'; - + if (mysql_version() >= 50503) query('SET NAMES utf8mb4') or error(db_error()); else @@ -85,11 +86,11 @@ function sql_open() { return $pdo; } catch(PDOException $e) { $message = $e->getMessage(); - + // Remove any sensitive information $message = str_replace($config['db']['user'], 'hidden', $message); $message = str_replace($config['db']['password'], 'hidden', $message); - + // Print error error(_('Database error: ') . $message); } @@ -98,7 +99,7 @@ function sql_open() { // 5.6.10 becomes 50610 function mysql_version() { global $pdo; - + $version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION); $v = explode('.', $version); if (count($v) != 3) @@ -108,11 +109,11 @@ function mysql_version() { function prepare($query) { global $pdo, $debug, $config; - + $query = preg_replace('/``('.$config['board_regex'].')``/u', '`' . $config['db']['prefix'] . '$1`', $query); - + sql_open(); - + if ($config['debug']) return new PreparedQueryDebug($query); @@ -121,13 +122,14 @@ function prepare($query) { function query($query) { global $pdo, $debug, $config; - + $query = preg_replace('/``('.$config['board_regex'].')``/u', '`' . $config['db']['prefix'] . '$1`', $query); - + sql_open(); - + 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()); } $start = microtime(true); diff --git a/inc/functions.php b/inc/functions.php index 515e3e55..18e4b06d 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -64,7 +64,7 @@ function loadConfig() { } - if (isset($config['cache_config']) && + if (isset($config['cache_config']) && $config['cache_config'] && $config = Cache::get('config_' . $boardsuffix ) ) { $events = Cache::get('events_' . $boardsuffix ); @@ -83,7 +83,7 @@ function loadConfig() { else { $config = array(); - reset_events(); + reset_events(); $arrays = array( 'db', @@ -283,7 +283,7 @@ function loadConfig() { if ($config['recaptcha']) require_once 'inc/lib/recaptcha/recaptchalib.php'; - + if ($config['cache']['enabled']) require_once 'inc/cache.php'; @@ -310,7 +310,7 @@ function loadConfig() { if (is_array($config['anonymous'])) $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; - + if ($config['debug']) { if (!isset($debug)) { $debug = array( @@ -350,7 +350,7 @@ function basic_error_function_because_the_other_isnt_loaded_yet($message, $prior '
This alternative error page is being displayed because the other couldn\'t be found or hasn\'t loaded yet.