note 96122 deleted from function.file-get-contents by danbrown

From: Date: Wed, 10 Feb 2010 02:39:10 +0000
Subject: note 96122 deleted from function.file-get-contents by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165817@lists.php.net to get a copy of this message
Note Submitter: e-mike ---- Simple cache (for more advanced see Zend Cache) <?php /* @param filename string * @param data mixed[optional] <p>if data given always refresh</p> * @param lifetime int[optional] <p>seconds</p> * @return mixed Returns sting on file exist and not expired or false on file not exist or expired */ function file_cache_contents($filename, $data = NULL, $lifetime = 3600) { $lifetime = date('Y-m-d H:i:s', time() - $lifetime); /* If data > always set file and return data * If exists and not expired > get and return data * Other posibilities > return false */ if ( ! is_null($data)) { file_put_contents($filename, $data); return $data; } else if (file_exists($filename) && date('Y-m-d H:i:s', filemtime($filename)) > $lifetime) { return file_get_contents($filename); } return false; } ?>

« previous php.notes (#165817) next »