In-depth understanding of PHP principles of execution cycle analysis, in-depth understanding of php_php tutorials

Source: Internet
Author: User
Tags php regular expression vars

In-depth understanding of PHP principles of execution cycle analysis, in-depth understanding of PHP


This article describes the PHP principle of the execution cycle. Share to everyone for your reference, as follows:

The execution cycle of PHP, from the first PHP script we wrote to the last script is executed, the results are executed, this process can be divided into the following stages:

First of all, Zend Engine (ZE), call the lexical analyzer (Lex generated, source file in zend/zend_language_sanner.l), the PHP source file we want to execute, remove the space, comment, split into one token.

Then, Ze will get the token forward to the parser (YACC generated, the source file in Zend/zend_language_parser.y), the generation of a opcode,opcode generally in the form of an OP array exists, It is the intermediate language that PHP executes.

Finally, Ze calls Zend_executor to execute the OP array, outputting the result. (That is, convert the source file into a machine language and then run it on the virtual machine.) )

Ze is a virtual machine, it is because of its existence, so that we can write PHP script, there is no need to consider what the operating system type is, this is the reason for PHP portability. Ze is a CISC (complex instruction processor) that supports 150 instructions (specific instructions in zend/zend_vm_opcodes.h), ranging from the simplest zend_echo (ECHO) to the complex Zend_include_or_eval ( Include,require), all of the PHP we write will eventually be processed into the sequence of these 150 commands (OP code), which is eventually executed .

PHP is a scripting language, that is, the user-written PHP code will eventually be interpreted by the PHP interpreter execution, all the written PHP code will be translated into PHP virtual machine ze virtual instruction (opcodes) to execute.

What about our PHP script, eventually being "translated"? In other words, what does op code look like? opcode is a PHP script-compiled intermediate language .

There is already such a module in Pecl, using the VLD (Vulcan Logic dissassembler) module developed by Derick Rethans. You just have to download the module and load it into PHP, and you can get the results of the script translation by simply setting it up.

Installation and application of the 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//do not need make

Edit the php.ini file and activate the VLD extension.

Instance:

Create a file, such as: hello.php

<?php  echo ' Hello, world ';? >

Perform:

[Root@localhost html]#/usr/local/php/bin/php-dvld.active=1 hello.phpbranch analysis from Position:0return Foundfilename:    /var/www/html/hello.phpfunction name: (null) Number of ops:3compiled vars:noneline   # op              Fetch     ext return operands-------------------------------------------------------------------------------  2   0 ECHO                           ' hello%2c+world. '  4   1 RETURN                          1     zend_handle_exceptionhello, world.

See another:

[Root@localhost html]# vi vld.php<?php  $i = "This is a string";  I am Comments  echo $i. ' That have been echoed on screen ';? >

Perform:

[Root@localhost html]#/usr/local/php/bin/php-dvld.active=1 vld.phpbranch analysis from Position:0return Foundfilename:    /var/www/html/vld.phpfunction name: (null) Number of ops:5compiled VARs:!0 = $iline   # op              Fetch     ext return operands-------------------------------------------------------------------------------  3   0 ASSIGN                          ! 0, ' this+is+a+string '  7   1 CONCAT  to! 0, ' +that+has+been+echoed+on+ Screen '     2 ECHO-  3 RETURN                          1 Zend_handle_exceptionthis is a string that had     been echoed on Screen

Note: Zend_handle_exception is the 149th directive in Zend/zend_vm_opcodes.h

Compiled VARs:!0 = $i Here is a variable named "I" that gets the variable in!0 (*zval).
#0 Assign the string "This+is+a+string" (ASSIGN) to!0
#1 String Connection
#2 Display

These intermediate codes are executed directly by the Zend VM (Zend virtual machine). The function that is actually responsible for execution is: Zend_execute (zend_execute.h).

More interested in PHP related content readers can view the site: "PHP Math Skills Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP array" operation Skills Daquan, " PHP Sorting algorithm Summary, "PHP Common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string Usage Summary" and " A summary of common PHP database operation techniques

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133036.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133036.html techarticle in-depth understanding of PHP principles of the execution cycle analysis, in-depth understanding of PHP This article describes the PHP principle of the execution cycle. Share to everyone for your reference, as follows: Php execution cycle, from the original ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.