So I changed this:
Code: Select all
public function get($key) {
$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');
if ($files) {
$handle = fopen($files[0], 'r');
flock($handle, LOCK_SH);
$data = fread($handle, filesize($files[0]));
flock($handle, LOCK_UN);
fclose($handle);
return json_decode($data, true);
}
return false;
}
Code: Select all
public function get($key) {
$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');
if (!empty($files) && file_exists($files[0]) && filesize($files[0]) > 0) {
$handle = fopen($files[0], 'r');
if ($handle) {
// Lock for shared reading
if (flock($handle, LOCK_SH)) {
$data = fread($handle, filesize($files[0]));
flock($handle, LOCK_UN); // Unlock
} else {
$data = '';
}
fclose($handle);
return json_decode($data, true);
}
}
return false;
}
Thanks.
EDIT: Note, I implemented this solution after I deleted files that were filling up my server and refreshed the cache on in the admin and the problem did not resolve itself. So I'm not 100% certain this actually fixed the issue, or the deletion of the files finally caught up....but the site kicked in as soon as I saved this code.
A secondary question, when something like this happens (if this was due to no space being available), could I implement code that could send me an email that the server space is filled up, or does this cripple any action on the front end?