Home >php教程 >PHP源码 >php 读写缓存文件实例 var_export

php 读写缓存文件实例 var_export

WBOY
WBOYOriginal
2016-06-08 17:28:311288browse
<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();

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn