加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

使用PHP缓存MySQL查询结果的最简单的方法?

发布时间:2020-12-13 16:40:42 所属栏目:PHP教程 来源:网络整理
导读:每次有人进入我的页面list.php?id = xxxxx它会重新查询一些 MySQL查询来返回: $ids = array(..,..,..); // not big array - not longer then 50 number records$thumbs = array(..,..); // not big array - not longer then 50 text records$artdesc = "so
每次有人进入我的页面list.php?id = xxxxx它会重新查询一些 MySQL查询来返回:
$ids = array(..,..,..); // not big array - not longer then 50 number records
$thumbs = array(..,..); // not big array - not longer then 50 text records
$artdesc = "some text not very long"; // text field

因为我进行查询的数据库是相当大的我想缓存这个结果24小时在也许一个文件,如xxxxx.php在/ cache /目录,所以我可以使用include(“xxxxx.php”)如果存在的话(或txt文件??或任何其他方式)

因为有非常简单的数据,我相信可以使用几行PH??P行,而不需要使用memcached或其他专业对象.

成为我的PHP非常有限可以有人只是放置PHP主线(或代码)这个任务?

我真的会非常感谢!

缓存PHP数组很简单:
file_put_contents($path,'<?php return '.var_export($my_array,true).';?>');

然后你可以读出来:

if (file_exists($path)) $my_array = include($path);

您可能还需要look into ADOdb,内部提供缓存.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读