PHP principle execution cycle example analysis
This article mainly introduces the in-depth understanding of the execution cycle of PHP principles, and briefly analyzes the relevant principles of the PHP program from editing to lexical analysis, syntax analysis and interpretation execution. Friends in need can refer to the following
PHP execution cycle, from the initial PHP script we wrote -> to the final script being executed -> getting the execution result, this process can actually be divided into the following stages:
First , Zend Engine (ZE), calls the lexical analyzer (generated by Lex, the source file is in Zend/zend_language_sanner.l), removes spaces and comments from the PHP source file we want to execute, and divides it into tokens one by one.
Then, ZE will forward the obtained token to the syntax analyzer (generated by yacc, the source file is in Zend/zend_language_parser.y), and generate opcodes one by one. The opcodes generally exist in the form of op array. It is the intermediate language for PHP execution.
Finally, ZE calls zend_executor to execute op array and output the results. (That is, convert the source file into machine language and then run it on a virtual machine.)
ZE is a virtual machine. It is precisely because of its existence that we can write PHP scripts without any need for Consider the type of operating system you are running on, this is why PHP is portable. ZE is a CISC (Complex Instruction Processor), which supports 150 instructions (specific instructions are in Zend/zend_vm_opcodes.h), including the simplest ZEND_ECHO (echo) to the complex ZEND_INCLUDE_OR_EVAL (include, require), All the PHP we write will eventually be processed into a sequence of these 150 instructions (op code), and will eventually be executed.
PHP is a scripting language, that is to say, the PHP code written by the user will eventually be interpreted and executed by the PHP interpreter. All PHP codes written will be translated into the PHP virtual machine ZE virtual instructions (OPCODES) to execute.
So what will our PHP script be "translated" into in the end? In other words, what does the op code look like? Opcode is an intermediate language compiled from PHP scripts.
There is already such a module in PECL, using the VLD (Vulcan Logic Dissassembler) module developed by Derick Rethans. You only need to download this module and load it into PHP, and you can get the result of script translation through simple settings.
Installation and application of VLD module:
[root@localhost software]# tar zxvf vld-0.9.1.tgz.gz [root@localhost vld-0.9.1]# /usr/local/php/bin/phpize [root@localhost vld-0.9.1]# ./configure --with-php-config=/usr/local/php/bin/php-config [root@localhost vld-0.9.1]# make install //不需要make
Edit the php.ini file and activate the vld extension.
Example:
Create a file, such as: hello.php
<?php echo 'hello, world.'; ?>
Execute:
[root@localhost html]# /usr/local/php/bin/php -dvld.active=1 hello.php Branch analysis from position: 0 Return found filename: /var/www/html/hello.php function name: (null) number of ops: 3 compiled vars: none line # op fetch ext return operands ------------------------------------------------------------------------------- 2 0 ECHO 'hello%2C+world.' 4 1 RETURN 1 2* ZEND_HANDLE_EXCEPTION hello, world.
Watch another:
[root@localhost html]# vi vld.php <?php $i = "This is a string"; //I am comments echo $i. ' that has been echoed on screen'; ?>
Execute:
[root@localhost html]# /usr/local/php/bin/php -dvld.active=1 vld.php Branch analysis from position: 0 Return found filename: /var/www/html/vld.php function name: (null) number of ops: 5 compiled vars: !0 = $i line # op fetch ext return operands ------------------------------------------------------------------------------- 3 0 ASSIGN !0, 'This+is+a+string' 7 1 CONCAT ~1 !0, '+that+has+been+echoed+on+screen' 2 ECHO ~1 10 3 RETURN 1 4* ZEND_HANDLE_EXCEPTION This is a string that has been echoed on screen
Note: ZEND_HANDLE_EXCEPTION is the 149th instruction in Zend/zend_vm_opcodes.h
compiled vars: !0 = $i Here is the variable name "i" The variable is at !0 (*zval).
#0 Assign the string "this is a string" (ASSIGN) to !0
#1 String connection
#2 Display
These intermediate codes will be used by Zend VM (Zend virtual machine) is executed directly. The function actually responsible for execution is: zend_execute (zend_execute.h).
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to use PHP to implement regular capture of the URL in the page
Identity card verification based on PHP Code verification calculation method
Based on PHP using locking to realize the code grabbing function under concurrent circumstances
The above is the detailed content of PHP principle execution cycle example analysis. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
