缓存PHP数组 [英] Caching a PHP Array

查看:81
本文介绍了缓存PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是IM创造了大量的嵌套PHP数组是解析从多个外部来源的信息。

My problem is im creating a large nested PHP array which is parsing information from multiple external sources.

在第一回,我想缓存此数据。

On the first return I would like to cache this data.

林pretty新缓存所以真的不知道我应该寻找,任何好的或坏的方法或即使这是常见的做法!用Google搜索,但没有真正发现任何像样的缓存小白。

Im pretty new to caching so don't really know what I should be looking for, any good or bad methods or even if this is common practise! Have googled but not really found anything decent for a cache noob.

林已经在使用Smarty的缓存我的网页内容(不含动态位),完成apache的调整,污染减量等,以提高性能,但页面加载仍远长。有时高达8秒!

Im already using smarty to cache my page content (excluding the dynamic bits), done apache tweaks, minifying etc to increase performance but page loading is still far to long. Sometimes upto 8 seconds!

使用PHP5与Smarty的。使用cURL解析,然后存储到阵列的XML。

Using PHP5 with Smarty. Using cURL to parse the XML which is then being stored into the array.

推荐答案

您可以尝试缓存到一个文件:

You could try to cache to a file:

file_put_contents("cache_file", serialize($myArray));

然后加载缓存:

$myArray = unserialize(file_get_contents("cache_file"));

这将工作,如果你的数组中的东西都序列化:没有DB连接或文件句柄,或者类似的东西。字符串和数字就好了。

This will work if the things in your array are serializable: no DB connections or file handles, or things like that. Strings and numbers are just fine.

如果你需要的东西票友可以使用基于内存的缓存就像memcached的。

If you need something fancier you can use a memory-based cache like memcached.

这篇关于缓存PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆