PHP Kernel exploration interpreter execution process

Source: Internet
Author: User
CLI (command line Interface) that is PHP, this SAPI is installed by default, after we install PHP on the server, we usually generate an executable file, assuming this file is/usr/local/bin/php, Then we can execute a PHP script with the following command under the shell:

Copy the Code code as follows:


/usr/local/bin/php-f test.php

Take the CLI SAPI as an example to parse the core part of PHP execution. CLI is the PHP command-line mode, this SAPI is installed by default, after the server side installed PHP, generated as an executable file, you can invoke PHP command in the shell to execute.

Copy the Code code as follows:


Php-f xx.php

Execution process:

Parse command line arguments;

Initializing the environment;

Compile and execute PHP code;

Clean up the environment and exit;

In the 3rd phase, how to execute a PHP script:

by calling Php_execute_script (Handle_file) to complete the third phase, the function will eventually call Zend_execute_scipts (...), which is a variable parameter function that can execute multiple PHP scripts at once.

In the Zend_execut_scripts (...) The functions in the core call the (Zend_compile_file) (Compile_file), (*zend_execute) (Zend_op_array) these two functions;

By invoking the PHP script file specified by the zend_compile_file compilation parameter, the function returns a zend_op_array structure pointer;

Zend_execute the passed-in parameter is the return value of zend_compile_file, the opcode is executed.

These two functions are the Zend API, which is a function pointer that is assigned a specific method when the engine is initialized.

PS.: So why are these two Zend APIs a function pointer?

At the time of engine initialization, Zend_execute and Zend_compile_file will point to the default method when the engine is initialized. We can compile and execute the point of the rewrite function, which leaves a hook for us to extend the engine. For example: VLD points Zend_execute and zend_compile_file to their own functions encapsulated in the original function, adding the output of the opcode information.

The above describes the PHP kernel to explore the implementation of the interpreter, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.