PHP中有全局的跨请求跨会话状态吗?
我想缓存一些数据供我的所有请求使用。我想要一个内存缓存,它会在代码文件更改时刷新(信息是通过反射获得的,更改代码文件可能会使它无效)。如果没有第三方外部服务(如 memcached),这可能吗?
补充:我知道像 apache 这样的网络服务器会创建多个工作进程。如果他们每个人都有自己的缓存就可以了。
I'd like to cache some data to be used by all my requests. I'd like an in-memory cache that would get flushed upon the change of a code file (the information is obtained by reflection, and changing the code file will probably invalidate it). Is this possible without 3rd party external services (like memcached)?
Added: I know that webservers like apache create several worker processes. It's OK if they each have their own cache.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 APC 的缓存而不是 memcached。例如 apc_add 函数。不幸的是,APC 并不是标准安装的 php,所以它并不是真的没有第三方外部服务。
You could use APC's cache instead of memcached. For example the apc_add function. Unfortunately APC is not standard installed with php, so it's not really without a 3rd party external service.
不,PHP 没有像 Java 那样的应用程序范围。你能做的最好的事情就是会话范围。但是,您可以轻松设置 Memcached 之类的东西来模拟应用程序范围
Nope, PHP doesn't have an application scope like Java. The best you could do is session scope. However, you could easily setup something like Memcached to mimic application scope