将PHP对象缓存到文件的方法? [英] Methods for caching PHP objects to file?

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

问题描述

在ASPNET中,我开始喜欢应用程序和缓存存储.他们很棒.对于未启动的用户,您只需将数据逻辑对象放入其中,嘿,您只需查询一次数据库即可获得少量数据.

In ASPNET, I grew to love the Application and Cache stores. They're awesome. For the uninitiated, you can just throw your data-logic objects into them, and hey-presto, you only need query the database once for a bit of data.

到目前为止,最好的ASPNET功能之一是IMO.

By far one of the best ASPNET features, IMO.

此后,我放弃了Windows for Linux,因此放弃了PHP,Python和Ruby for webdev.我使用PHP最多的原因是因为我开发了几个开源项目,全部使用PHP.

I've since ditched Windows for Linux, and therefore PHP, Python and Ruby for webdev. I use PHP most because I dev several open source projects, all using PHP.

不用说,我已经探讨了PHP在缓存数据对象方面所提供的功能.到目前为止,我玩过:

Needless to say, I've explored what PHP has to offer in terms of caching data-objects. So far I've played with:

  1. 序列化到文件(一个非常缓慢/昂贵的过程)
  2. 将数据以JSON/XML/plaintext/etc格式写入文件(对于读取操作而言甚至更慢)
  3. 将数据作为纯PHP写入文件(最快的读取速度,但是写操作相当复杂)

我现在要强调的是,我正在寻找一种不依赖第三方应用程序(例如memcached)的解决方案,因为这些应用程序安装在各种情况下,其中大多数没有安装权限(例如:廉价的共享托管帐户).

I should stress now that I'm looking for a solution that doesn't rely on a third party app (eg memcached) as the apps are installed in all sorts of scenarios, most of which don't have install rights (eg: a cheap shared hosting account).

所以回到我现在正在做的事情,是否坚持文件安全性?生产服务器安全性中的Rule 1始终禁用文件写入功能,但是我真的看不到任何方法如果无法编写PHP,则可以进行缓存.是否有任何提示和/或技巧可以提高安全性?

So back to what I'm doing now, is persisting to file secure? Rule 1 in production server security has always been disable file-writing, but I really don't see any way PHP could cache if it couldn't write. Are there any tips and/or tricks to boost the security?

还有其他我遗忘的文件保存方法吗?

在受限"环境中还有更好的缓存方法吗?

推荐答案

序列化是相当安全且常用的方法.但是,还有另一种方法,那就是缓存到内存.查看 memcached 本文有关PHP中不同的缓存技术也许也很有趣.

Serializing is quite safe and commonly used. There is an alternative however, and that is to cache to memory. Check out memcached and APC, they're both free and highly performant. This article on different caching techniques in PHP might also be of interest.

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

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