From bb2fe17a030a5e5d4e0dbaa0aea8380c2e99285d Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 13 Mar 2012 01:39:31 +0000 Subject: [PATCH] Homepage: Use a stream read in ContentCache::retrieve() Retrieving the contents of large files was generating warnings... --- web/classes/contentcache.class.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/web/classes/contentcache.class.php b/web/classes/contentcache.class.php index 28017c830a..674dde268e 100644 --- a/web/classes/contentcache.class.php +++ b/web/classes/contentcache.class.php @@ -93,18 +93,24 @@ public function isPresent($file) * Attempt to retrieve a content element from the cache, copying * its contents into a string. * - * @param file (String) File name to retrieve. + * @param relPath (String) File name to retrieve. * @return (Boolean) FALSE if the content element could not be * found, else the content as a string. */ - public function retrieve($file) + public function retrieve($relPath) { - $file = FrontController::nativePath($this->_docRoot."/$file"); + $path = FrontController::nativePath($this->_docRoot."/$relPath"); - if(!file_exists($file)) - throw new Exception(sprintf('file %s not present in content cache.', $file)); + if(!file_exists($path)) + throw new Exception(sprintf('file %s not present in content cache.', $relPath)); - return file_get_contents($file); + if($stream = fopen($path, 'r')) + { + $contents = stream_get_contents($stream); + fclose($stream); + return $contents; + } + return ""; } /**