opcache is used to cache the opcode generated by zend engine compilation, so there is no need to compile it next time.
I recently heard about php jit and took a look at the concept of jit. The description is as follows:
JIT compilation (just-in-time compilation), that is, just-in-time compilation, in a narrow sense refers to compiling a certain piece of code when it is about to be executed for the first time, and then directly executing it without compilation. It is a type of dynamic compilation. special case.
What is the difference between php's jit and opcache?
源代码(人认识)->字节码(解释器认识)->机器码(硬件认识)
来看下PHP的执行流程,假设有个a.php文件,不启用opacache的流程如下:
a.php->经过zend编译->opcode->PHP解释器->机器码
启用opacache的流程如下
a.php->查找opacache缓存,如果没有则进行zend编译为opcode并缓存->opacode->PHP解释器->机器码
启用jit的流程如下
a.php->编译->机器码
以后都只执行机器码,不编译,效率上高了很多
JIT这个概念其实来自Java,在Java里,JIT编译器是将字节码编译为机器码的过程。
如果把PHP和Java做对应,那么PHP编译成OpCode的过程就是Java编译为字节码的过程,而引申起来,PHP的JIT,也就是把OpCode编译为机器码的过程。
更简单的说,PHP程序编译成OpCode,而后交给PHP解释器取执行,这样的过程还是一个解释执行的过程。而如果通过JIT编译为机器码,那么程序的执行效率是可以得到大幅提高的。
目前热门的几个脚本语言,都已经拥有了自己的JIT,唯独PHP这方面还有欠缺。所以,有所期待吧,期待PHP 8