diff --git a/inc/_LOGGER_.php b/inc/_LOGGER_.php new file mode 100755 index 00000000..fc427074 --- /dev/null +++ b/inc/_LOGGER_.php @@ -0,0 +1,69 @@ + $value) { + $function = isset($value['function']) ? $value['function'] : "unknown"; + $file = isset($value['file']) ? $value['file'] : "unknown"; + $line = isset($value['line']) ? $value['line'] : "unknown"; + + $message = isset($value['args']) ? print_r($value['args'], true) : "unknown"; + + // if ($key == 0) { + // $log .= " " . $function . " at: " . $file . " : " . $line . "\n"; + // $log .= " " . $message[1] . "\n"; + // continue; + // } + $log .= " " . $function . " at: " . $file . " : " . $line . "\n"; + } + } catch (Exception $e) { + echo '
'; + echo "Original stack trace: \n"; + echo $e->getMessage(); + print_r($callStack->getTrace()); + echo ''; + echo '
'; + echo 'Current stack trace: \n'; + echo $e->getMessage(); + print_r($e->getTrace()); + echo ''; + + die("Unable to parse stack trace"); + } + self::log($log, $includeDate); + } +} \ No newline at end of file diff --git a/inc/cache.php b/inc/cache.php index 293660fd..fe508610 100644 --- a/inc/cache.php +++ b/inc/cache.php @@ -12,6 +12,7 @@ defined('TINYBOARD') or exit; class Cache { private static function buildCache(): CacheDriver { global $config; + $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv"); switch ($config['cache']['enabled']) { case 'memcached': @@ -20,12 +21,31 @@ class Cache { $config['cache']['memcached'] ); case 'redis': + $host = $config['cache']['redis'][0] ?? 'localhost'; + $port = $config['cache']['redis'][1] ?? 6379; + $password = $config['cache']['redis'][2] ?? ''; + $database = $config['cache']['redis'][3] ?? 1; + + if ($isDocker) { + $host = getenv('VICHAN_REDIS_HOST') ?: $host; + $port = getenv('VICHAN_REDIS_PORT') ?: $port; + $password = getenv('VICHAN_REDIS_PASSWORD') ?: $password; + $database = getenv('VICHAN_REDIS_DATABASE') ?: $database; + } + // $log->log("Cache info:\n" + // . 'Cache driver: redis' . "\n" + // . '├ Redis host: ' . $host . "\n" + // . '├ Redis port: ' . $port . "\n" + // . '├ Redis password: ' . str_repeat('*', strlen($password)) . "\n" + // . '└ Redis database: ' . $database . "\n" + // ); + return new RedisCacheDriver( $config['cache']['prefix'], - $config['cache']['redis'][0], - $config['cache']['redis'][1], - $config['cache']['redis'][2], - $config['cache']['redis'][3] + $host, + $port, + $password, + $database ); case 'apcu': return new ApcuCacheDriver; diff --git a/inc/config.php b/inc/config.php index e7655634..8341a072 100644 --- a/inc/config.php +++ b/inc/config.php @@ -143,27 +143,10 @@ // Configure cache if ($redis_enabled) { $config['cache']['enabled'] = 'redis'; - $config['cache']['redis'] = [ - 'host' => getenv('VICHAN_REDIS_HOST') ?: 'localhost', - 'port' => (int)(getenv('VICHAN_REDIS_PORT') ?: 6379), - 'password' => getenv('VICHAN_REDIS_PASSWORD') ?: '', - 'database' => 1, - ]; } else { $config['cache']['enabled'] = 'php'; } - // Configure sessions to use Redis if enabled - if ($redis_enabled) { - $config['session']['enabled'] = 'redis'; - $config['session']['redis'] = [ - 'host' => getenv('VICHAN_REDIS_HOST') ?: 'localhost', - 'port' => (int)(getenv('VICHAN_REDIS_PORT') ?: 6379), - 'password' => getenv('VICHAN_REDIS_PASSWORD') ?: '', - 'database' => 1, - ]; - } - // Cache timeout for cached objects $config['cache']['timeout'] = 60 * 60 * 48; // 48 hours @@ -1869,6 +1852,15 @@ // Enable public logs? 0: NO, 1: YES, 2: YES, but drop names $config['public_logs'] = 0; +/* + * ==================== + * Docker settings + * =================== + */ + + $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv"); + $config['docker'] = $isDocker; + /* * ==================== * Events (PHP 5.3.0+)