Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Swoole\Cache; /** * memcache * Key-Value * @author Tianfeng.Han * @pac..
Decoded Output download
<?php
namespace Swoole\Cache;
/**
* memcache
* Key-Value
* @author Tianfeng.Han
* @package Swoole
* @subpackage cache
*/
class FileCache implements \Swoole\IFace\Cache
{
protected $config;
function __construct($config)
{
if (!isset($config['cache_dir']))
{
throw new \Exception(__CLASS__.": require cache_dir");
}
if (!is_dir($config['cache_dir']))
{
mkdir($config['cache_dir'], 0755, true);
}
$this->config = $config;
}
protected function getFileName($key)
{
$file = $this->config['cache_dir'] . '/' . trim(str_replace('_', '/', $key), '/');
$dir = dirname($file);
if(!is_dir($dir))
{
mkdir($dir, 0755, true);
}
return $file;
}
function set($key, $value, $timeout=0)
{
$file = $this->getFileName($key);
$data["value"] = $value;
$data["timeout"] = $timeout;
$data["mktime"] = time();
return file_put_contents($file, serialize($data));
}
function get($key)
{
$file = $this->getFileName($key);
if(!is_file($file)) return false;
$data = unserialize(file_get_contents($file));
if (empty($data) or !isset($data['timeout']) or !isset($data["value"]))
{
return false;
}
//
if ($data["timeout"] != 0 and ($data["mktime"] + $data["timeout"]) < time())
{
$this->delete($key);
return false;
}
return $data['value'];
}
function delete($key)
{
$file = $this->getFileName($key);
return unlink($file);
}
} ?>
Did this file decode correctly?
Original Code
<?php
namespace Swoole\Cache;
/**
* memcache
* Key-Value
* @author Tianfeng.Han
* @package Swoole
* @subpackage cache
*/
class FileCache implements \Swoole\IFace\Cache
{
protected $config;
function __construct($config)
{
if (!isset($config['cache_dir']))
{
throw new \Exception(__CLASS__.": require cache_dir");
}
if (!is_dir($config['cache_dir']))
{
mkdir($config['cache_dir'], 0755, true);
}
$this->config = $config;
}
protected function getFileName($key)
{
$file = $this->config['cache_dir'] . '/' . trim(str_replace('_', '/', $key), '/');
$dir = dirname($file);
if(!is_dir($dir))
{
mkdir($dir, 0755, true);
}
return $file;
}
function set($key, $value, $timeout=0)
{
$file = $this->getFileName($key);
$data["value"] = $value;
$data["timeout"] = $timeout;
$data["mktime"] = time();
return file_put_contents($file, serialize($data));
}
function get($key)
{
$file = $this->getFileName($key);
if(!is_file($file)) return false;
$data = unserialize(file_get_contents($file));
if (empty($data) or !isset($data['timeout']) or !isset($data["value"]))
{
return false;
}
//
if ($data["timeout"] != 0 and ($data["mktime"] + $data["timeout"]) < time())
{
$this->delete($key);
return false;
}
return $data['value'];
}
function delete($key)
{
$file = $this->getFileName($key);
return unlink($file);
}
}
Function Calls
None |
Stats
MD5 | d57c742dfb33273cdc5ea654112986c7 |
Eval Count | 0 |
Decode Time | 113 ms |