取消设置 php 中的变量会影响缓存吗?
也许这是一个愚蠢的问题,但在我的页面末尾,我将所有变量设置为 null,然后取消设置它们,以提高性能,尽管我知道,它可能对性能几乎没有影响,但即便如此,这会对任何缓存模块(例如 、varnish、apc 或 memcached)产生影响吗?
Maybe this is a stupid question, but at the end of my pages i set all of the variables to null and then unset them, for performance, even though, i know, it probably has little to no effect on performance, but even so, would that have any effect on any caching modules, such as , varnish, apc, or memcached?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了(也许)垃圾收集之外,它不会影响任何事情。请此处了解 APC 的工作原理。大多数其他缓存插件的工作方式相同。
你会注意到像 APC 这样的缓存器(顺便说一下,memcached 与这个问题无关——Varnish 也没有)仍然解析所有 PHP。取消设置变量可能做的唯一事情是导致垃圾收集器启动。如果 GC 启动,您可能会看到速度减慢(然后加速)。尽管如此,它并不是很确定。通常,PHP 在垃圾收集方面非常出色,因此您不必担心它,除非您试图模拟某种 RAII 行为。
Varnish 是一个 HTTP 加速器(与 PHP 无关)。 memcached 是一个基于内存的分布式信息存储(也与 PHP 的内部工作原理无关)。
It doesn't affect anything except for (maybe) the garbage collection. Look here at how APC works. Most other caching plugins work the same way.
You'll notice that cachers like APC (memcached has nothing to do with this question, by the way - and neither does Varnish) still parse all PHP. The only thing unsetting variables may do is cause the garbage collector to kick in. If the GC kicks in, you may see a slow-down (and then, a speed-up). With that said, though, it's not very deterministic. Usually PHP is pretty good about garbage collection, so you shouldn't worry about it unless you're trying to emulate some sort of RAII behavior.
Varnish is an HTTP accelerator (that has nothing to do with PHP). memcached is a distributed memory-based information store (which also has nothing to do with PHP's inner workings).