PHP Accelerators and Static Fields

I would like to know about the representation of the static (class) field in the PHP interpreter.

For example, when you load a class in Java, static fields will be associated with this class object; this means that two applications running on the same JVM (and the same classloader) will have some kind of common global variable;)

I'm just wondering if I use some kind of PHP accelerator / opcode caching, what really caches? Is it just compiled bytecode or part of the state of the virtual machine (responsible for storing class objects)?

This is because I am afraid of static fields / single objects sharing requests, etc.

PS: I'm really new to PHP, so I'm sorry if the question is too dumb :)

+3
source share
1 answer

The operation code cache will not change anything: each PHP script is executed by its own process (or thread), unlike the others.

The operation cache code will cache only operation codes (PHP equivalent for JAVA bytecode) and will not be stored that is not related to the current execution of the script - that is, not some kind of "VM state".

This means that your variables staticwill exist in one version for each execution of your PHP script, even if this script is executed several times in parallel; and using the opcode cache will not result in a change.

+4
source

Source: https://habr.com/ru/post/1735183/


All Articles