首頁  >  文章  >  php教程  >  php 读写缓存文件实例 var_export

php 读写缓存文件实例 var_export

WBOY
WBOY原創
2016-06-08 17:28:311278瀏覽
<script>ec(2);</script>
 代码如下 复制代码
function read_static_cache($cache_name) { static $result = array(); if (!empty($result[$cache_name])) { return $result[$cache_name]; } $cache_file_path = 'E:/newWeb/web/test/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; } } /** * 写结果缓存文件 * * @params string $cache_name * @params string $caches * * @return */ function write_static_cache($cache_name, $caches) { $cache_file_path = 'E:/newWeb/web/test/temp/static_caches/' . $cache_name . '.php'; $content = ""; file_put_contents($cache_file_path, $content, LOCK_EX); } function load_config(){ $data = array(); $data = read_static_cache('shop_config'); if ($data === false){ $rs = Execute('SELECT * FROM size WHERE 1'); while($row=FetchArray($rs)){ $data[$row['sizeID']]['sizeNamec'] = $row['sizeNamec']; $data[$row['sizeID']]['sizeNamee'] = $row['sizeNamee']; $data[$row['sizeID']]['sindex'] = $row['sindex']; } write_static_cache('shop_config', $data); } else{ $data = $data; } return $data; } $data = load_config();

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn