如何在php中在应用程序级别保存变量? [英] How to save a variable at application level in php?

查看:67
本文介绍了如何在php中在应用程序级别保存变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php中将应用程序级别的变量(对于所有用户相同)保存,一段时间后会更新?

How to save a variable at application level(same for all users) in php which will get updated after some time?

我试图找到它.我找到了以下解决方案:

I've tried to find about it. I've found the following solutions:

  1. 使用文件处理实现.
  2. 缓存(Memcache或APC)
  3. 使用数据库支持实现

2被认为是最佳(AFAIK). (我不允许在服务器上安装任何东西)

2 is considered as best (AFAIK). (I'm not allowed to install anything on the Server)

另外两个(上面提到的)或其他任何选项又如何实现呢?我有点担心,因为访问量适中(但是坏的是我仍然不能使用任何缓存机制).我们只需要在应用程序级别保存大约255个字节的缓冲区内容即可.

What about other two (mentioned above) or any other options and how I can implement those? I'm bit concerned because traffic is moderately high (but the bad thing is that I still can't use any cache mechanism). We just need to save the contents of buffer of around 255 bytes at application level.

任何片段,指针或任何形式的帮助都将受到高度赞赏.

Any snippets, pointers or help of any sort would be highly appreciated.

谢谢.

推荐答案

您需要一个永久性的存储空间,而不是缓存或类似的东西. 如果您的应用程序尚未使用数据库,则可以选择以下几个选项:

You need a permanent storage, not cache or something like that. If your application doesn't use a database already, there are several options you can choose from:

  • 写入文本文件,一个简单的一行条目或最好以xml,json之类的格式
  • 写入轻量级存储引擎,例如sqlite,简单存储(Amazon S3)

如果您的应用已使用数据库,为什么不将这些数据存储在单独的表中?

If your app uses a database already, why not store that data in a separate table?

这篇关于如何在php中在应用程序级别保存变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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