PHP kernel Exploration Interpreter's execution process _php instance

Source: Internet
Author: User
Tags install php php script sapi zend

CLI (command line Interface) is the command-line mode of PHP, now this SAPI is installed by default, after we install PHP on the server, we typically generate an executable file, assuming this file is/usr/local/bin/php, Then we can execute a PHP script under the shell with the following command:

Copy 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. The CLI is the PHP command-line mode, which is installed by default, and is generated as an executable file after the server has installed PHP, and can be executed by invoking the PHP command in the shell SAPI.

Copy Code code as follows:

Php-f xx.php

Execution process:

Parse command line arguments;

initialization of the environment;

Compile and execute PHP code;

Clean up the environment, exit;

In the 3rd phase, how to execute the 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 a time.

In Zend_execut_scripts (...) The core of the function calls (Zend_compile_file) (Compile_file), (*zend_execute) (Zend_op_array) the two functions;

By calling 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 parameter is the return value of the zend_compile_file, the execution of the opcode is started.

These two functions are the Zend API, a function pointer that assigns a specific method when the engine initializes.

PS.: So why are the two Zend APIs the function pointers?

When the engine initializes, Zend_execute and Zend_compile_file point to the default method when the engine initializes. We can point to compiling and executing the rewrite function so that we leave a hook when we 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 opcode information.

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.