| Server IP : 45.40.142.9 / Your IP : 216.73.216.250 Web Server : Apache System : Linux s45-40-142-9.secureserver.net 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : bayspec ( 506) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/bayspec/public_html/system/library/cache/ |
Upload File : |
<?php
namespace Cache;
class File {
private $expire;
public function __construct($expire = 3600) {
$this->expire = $expire;
$files = glob(DIR_CACHE . 'cache.*');
if ($files) {
foreach ($files as $file) {
$time = substr(strrchr($file, '.'), 1);
if ($time < time()) {
if (file_exists($file)) {
unlink($file);
}
}
}
}
}
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 unserialize($data);
}
return false;
}
public function set($key, $value) {
$this->delete($key);
$file = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.' . (time() + $this->expire);
$handle = fopen($file, 'w');
flock($handle, LOCK_EX);
fwrite($handle, serialize($value));
fflush($handle);
flock($handle, LOCK_UN);
fclose($handle);
}
public function delete($key) {
$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');
if ($files) {
foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
}
}
}
}
}