Compare commits

...

11 Commits

Author SHA1 Message Date
czaks
3879e713a5 hide 404.php when unneeded and unconfigured :^) 2016-01-26 01:50:51 +01:00
czaks
aeba30e4e1 Revert "explain what's going on in this fork"
This reverts commit 3d5404d589df5b6c3ecb1e5b0bc90c3c13caa9e9.
2016-01-26 01:48:09 +01:00
czaks
c0b7d97ec1 Revert "fix formatting"
This reverts commit 6456924537503f5bcf7b60037ba4ce1902e1f518.
2016-01-26 01:48:01 +01:00
czaks
ac4c2e0370 clean up the code a bit, fix a few bugs 2016-01-26 01:44:56 +01:00
czaks
d918fddea1 Merge https://github.com/odilitime/vichan into odilitime 2016-01-26 01:13:20 +01:00
R Odili
6456924537 fix formatting 2015-12-22 02:09:38 -05:00
R Odili
3d5404d589 explain what's going on in this fork 2015-12-22 02:08:25 -05:00
R Odili
d5e11b8fd9 change query to only explain selects
mysql doesn't let you explain non-selects
2015-12-22 01:56:05 -05:00
root
499e609ec7 change file_* to use cache
This make all static files not written to disk but the memory instead thus reducing disk io
2015-12-22 01:53:45 -05:00
root
303ed52812 implement non-expiring store() function
this will allow longer term storage of data
2015-12-22 01:52:50 -05:00
root
b9e443a1e2 implement new 404 test handler
not efficent but if you're webserver can't pull from redis, this will work for a demo
2015-12-22 01:51:25 -05:00
5 changed files with 210 additions and 149 deletions

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);
?>

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

@ -90,7 +90,14 @@ class Cache {
case 'redis': case 'redis':
if (!self::$cache) if (!self::$cache)
self::init(); self::init();
if ($expires === FALSE) {
self::$cache->set($key, json_encode($value));
}
else {
self::$cache->setex($key, $expires, json_encode($value)); self::$cache->setex($key, $expires, json_encode($value));
}
break; break;
case 'apc': case 'apc':
apc_store($key, $value, $expires); apc_store($key, $value, $expires);

View File

@ -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
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

@ -643,6 +643,18 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
} }
} }
if ($config['files_in_cache']) {
Cache::set('vichan_filecache_'.$path, $data);
if ($config['gzip_static']) {
$bytes=strlen($data);
if ($bytes & ~0x3ff) {
Cache::set('vichan_filecache_'.$path.'.gz', gzencode($data));
} else {
Cache::delete('vichan_filecache_'.$path.'.gz');
}
}
}
else {
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);
@ -675,6 +687,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 +701,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 +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;
} }
$ret = @unlink($path);
Cache::delete('vichan_filecache_'.$path);
if ($config['gzip_static']) {
Cache::delete('vichan_filecache_'.$path.'.gz');
}
$ret = @unlink($path);
if ($config['gzip_static']) { if ($config['gzip_static']) {
$gzpath = "$path.gz"; $gzpath = "$path.gz";
@unlink($gzpath); @unlink($gzpath);
} }