开发者

PHP accelerators and static fields

开发者 https://www.devze.com 2022-12-22 05:04 出处:网络
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

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 stat开发者_运维技巧e (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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号