PHP 加速器和静态字段
我想了解 PHP 解释器中的静态(类)字段表示。
例如,当您在 Java 中加载一个类时,静态字段将与该 Class 对象关联;这意味着运行相同 JVM(和相同类加载器)的两个应用程序将具有某种共享全局变量;)
我只是想知道,如果我使用某种 PHP 加速器/操作码缓存,那么真正缓存的是什么?它只是编译后的字节码,还是一段VM状态(负责存储类对象)?
这是因为我害怕请求之间共享静态字段/单例对象等。
PS:我真的是一个 PHP 新手,所以如果这个问题太愚蠢了,我很抱歉:)
I would like to know about static (class) field representation within PHP interpreter.
For example, when you load a class in Java, static fields will be associated with that Class object; that means two applications running same JVM (and same classloader) will have some kind of shared global variable ;)
I'm just wondering, if I use some kind of PHP accelerator/opcode caching, what is that really cached? Is it just compiled bytecode, or a piece of VM state (responsible for storing class objects)?
It's because I'm afraid of static fields/singleton objects sharing between requests, etc.
P.S.: I'm really a PHP newbie, so I'm very sorry if the question is way too dumb :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
操作码缓存不会改变任何内容:每个 PHP 脚本都由自己的进程(或线程)执行,与其他脚本隔离。
操作码缓存只会缓存操作码(JAVA 字节码的 PHP 等价物),并且不会存储与当前脚本执行无关的内容,即不存储任何类型的“VM 状态” /em>”。
这意味着每次执行 PHP 脚本时,静态变量都将存在于一个版本中,即使该脚本并行执行多次;使用或不使用操作码缓存不会改变任何事情。
An opcode cache will not change anything : each PHP script is executed by its own process (or thread), in isolation from the others.
An opcode cache will only cache opcodes (the PHP equivalent of JAVA's bytecode), and will nor store not related to the current execution of the script -- i.e. not any kind of "VM state".
This means your
static
variables will exist in one version for each execution of your PHP script, even if that script is executed several times in parallel ; and using or not an opcode cache will not change a thing.