phpファイルにデータを書き込む
1070 ワード
**
*
*
* @params string $cache_name
* @params string $caches
*
* @return
*/
function write_static_cache($cache_name, $caches)
{
$cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';
$content = "";
$content .= "\$data = " . var_export($caches, true) . ";\r
";
$content .= "??>";
file_put_contents($cache_file_path, $content, LOCK_EX);
}
/**
*
*
* @params string $cache_name
*
* @return array $data
*/
function read_static_cache($cache_name)
{
static $result = array();
if (!empty($result[$cache_name]))
{
return $result[$cache_name];
}
$cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';
if (file_exists($cache_file_path))
{
include_once($cache_file_path);
$result[$cache_name] = $data;
return $result[$cache_name];
}
else
{
return false;
}
}