note 96122 added to function.file-get-contents
| From: | e-mike at osu1 dot php dot net | Date: | Tue, 09 Feb 2010 23:40:05 +0000 |
| Subject: | note 96122 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165810@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 91.199.167.223
Probable Submitter: 87.208.6.230
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit -- https://master.php.net/note/edit/96122
Del: integrated -- https://master.php.net/note/delete/96122/integrated
Del: useless -- https://master.php.net/note/delete/96122/useless
Del: bad code -- https://master.php.net/note/delete/96122/bad+code
Del: spam -- https://master.php.net/note/delete/96122/spam
Del: non-english -- https://master.php.net/note/delete/96122/non-english
Del: in docs -- https://master.php.net/note/delete/96122/in+docs
Del: other reasons-- https://master.php.net/note/delete/96122
Reject -- https://master.php.net/note/reject/96122
Search -- https://master.php.net/manage/user-notes.php