简体   繁体   中英

Is a local PHP include() file cached?

After doing some research i'm struggling to find a definitive answer on how and if a PHP include() file is cached.

The closest i've found is here but it doesn't quite make sense to me.

I have several methods that use other methods from different files and I want to avoid placing include()'s just at the top of the file but i'm not sure how this might affect performance.

Any help is appreciated.

PHP is an interpreted language. The default PHP runtime compiles PHP sourcecode to an intermediate representation called PHP bytecode which is then executed. A bytecode cache stores this compiled representation of PHP sourcecode in shared memory. This eliminates the need to load and compile sourcecode on each request which leads to a significant increase in performance (up to 70% more requests per second).

The basic idea, when executing a PHP script is in two steps:

  • First: the PHP code, written in plain-text, is compiled to opcodes
  • Then: those opcodes are executed . When you have one PHP script, as long as it is not modified, the opcodes will always be the same ; so, doing the compilation phase each time that script is to be executed is kind of a waste of CPU-time.

To prevent that redundant-compilation, there are some opcode caching mechanism that you can use.

Once the PHP script has been compiled to opcodes, those will be kept in RAM -- and directly used from memory the next time the script is to be executed ; preventing the compilation from being done again and again.

Read more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM