Get the App
SLTechnology News&Howtos  ›  Development  › 

An example Analysis of the OpCode principle of PHP

Shulou Source: shulou.com Published: 2022-06-03 20:23:03 11月12日 Update

This article mainly introduces the example analysis of PHP's OpCode principle, which is very detailed and has a certain reference value. Interested friends must read it!

The details are as follows:

OpCode is an intermediate language for compiling PHP scripts, like ByteCode for Java or MSL for .NET. This article is mainly based on "Understanding OPcode" and the Internet. According to personal understanding and modification, this article is specially recorded:

PHP Code:

PHP executes this code through the following four steps:

1. Scanning (Lexing) to convert PHP code into language snippets (Tokens)

2. Parsing, which converts Tokens into simple and meaningful expressions

3. Compilation, compiling the expression to Opocdes

4. Execution, execute Opcodes sequentially, one at a time, thus realizing the function of PHP script.

Note: some Cache, such as APC, can enable PHP to cache Opcodes, so that every time a request comes, there is no need to repeat the previous three steps, which can greatly improve the execution speed of PHP.

First of all, Zend/zend_language_scanner.c will analyze the input PHP code according to Zend/zend_language_scanner.l (Lex file) to get a "word". PHP4.2+ begins to provide a function called token_get_all, and this function can Scanning a piece of PHP code into Tokens.

Tags: Variables operands code results compilation analysis content characters beginnings expressions principles examples different and then functions that is operators time source code spaces Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Xiaomi Linux vpn