Member-only story
OPcache and Preloading in PHP
This is the second part of my blog series on PHP. In this post, we will cover OPcache and preloading.
Before starting this article, I recommend first reading “The Magic Behind PHP” for a better understanding of how PHP works.
What is OPcache?
In the left part (not cached) PHP’s internal working style is applied. We can see from this figure that the default (not optimized) PHP has a real bottleneck. For the same script, we are tokenizing, parsing, and compiling again and again. So this is not a good thing.
As developers, we can solve similar problems by applying cache strategies. So PHP developers did the same thing and introduced OPcache. with PHP 5.5. Before PHP supports internally there were several solutions and extensions for this problem. For example, APC, eAccelerator, and XCache.
After the compilation step, we store precompiled bytecodes in Shared Memory, and in the upcoming requests, PHP skips the parsing and compilation steps. This basically means “speed” :)