From c9a2fe5343c5e0307754c799a4a8d3173470c598 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sun, 28 Sep 2014 02:21:34 +0000 Subject: [PATCH] Improve 404 page performance so it can actually be used --- 404.php | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/404.php b/404.php index 364ae33a..5ac7f2ad 100644 --- a/404.php +++ b/404.php @@ -1,33 +1,34 @@ init(); +if (!is_dir($dir)) + mkdir($dir); -if($cache->get("404glob") == false){ -$files = glob("404/*.*"); -$cache->set("404glob", $files); -}else -$files = $cache->get("404glob"); +if ($config['cache']['enabled']) { + $files = cache::get('notfound_files'); +} -if(count($files) == 0) - $errorimage = ""; -else +if (!isset($files) or !$files) { + $files = array_diff(scandir($dir), array('..', '.')); + + if ($config['cache']['enabled']) { + cache::set('notfound_files', $files); + } +} + +if (count($files) == 0) { + $errorimage = false; +} else { $errorimage = $files[array_rand($files)]; +} $page = <<
-

404 Not Found

- - +

- EOT; -echo Element("page.html", array("config" => $config, "body" => $page, "title" => "")); +echo Element("page.html", array("config" => $config, "body" => $errorimage ? $page : "", "title" => "404 Not Found"));