PHP kernel exploration-interpreter Execution Process _ php instance

Source: Internet
Author: User
This article mainly introduces the execution process of the interpreter for PHP kernel exploration. For more information, see cli (Command Line Interface), which is the Command Line mode of PHP, now this SAPI is installed by default. After installing PHP on the server, an executable file is generated. Assume that this file is/usr/local/bin/php, in SHELL, run the following command to execute a PHP script:

The Code is as follows:


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

Take 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 PHP is installed on the server side, an executable file is generated. You can call the PHP Command in shell to execute it.

The Code is as follows:


PHP-f XX. php

Execution Process:

Parse command line parameters;

Initialize the environment;

Compile and execute PHP code;

Clean up the environment and exit;

How to execute the PHP script in the 3rd phase:

Call php_execute_script (handle_file) to complete the third stage. This function will eventually call zend_execute_scipts (... ), This function is a variable parameter function that can execute multiple PHP scripts at a time.

In zend_execut_scripts (.....) The core function calls the (zend_compile_file) (compile_file) and (* zend_execute) (zend_op_array) functions;

Call zend_compile_file to compile the php script file specified by the parameter. This function returns a structure pointer of zend_op_array;

The input parameter zend_execute is the return value of zend_compile_file, and opcode is executed.

These two functions are Zend APIs and are a function pointer. The specific method for assigning values when the engine is initialized is called.

Ps: Why are these two Zend APIs function pointers?

During engine initialization, zend_execute and zend_compile_file point to the default method during engine initialization. We can compile and execute the rewrite function, which leaves a hook for our extension engine. For example, vld points zend_execute and zend_compile_file to the function encapsulated by the original function and adds the opcode output.

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.