Where is the main entry point of php-src / PHP-Internals

What function or bit of code is the main entry point for executing / interpreting a PHP program in the source of PHP itself ? Based on the things that I looked at or read in books, I know that PHP is designed to work with any server (even the CLI command works by running the "SAPI command line", which acts as a mini-server designed to handle one request), and that the server will ask PHP to execute the program.

I know about life cycle functions minitand rinitthat serve as entry points for PHP extensions .

That I do not know where the PHP source code has this conversation with itself

Hey look, there is a PHP program in this file / line. I have to run it

I am not trying to accomplish any specific task here. I'm trying to understand how the inside of PHP does what it does, and find the main entry point where I can start executing it.

+6
source share
1 answer

Where is the entry point of any SAPI code?

CLI is a standalone application. Like any other application written in C, its entry point is a function main()(file sapi/cli/php_cli.c, line 1200):

int main(int argc, char *argv[])

CLI Windows, - main(), , - Windows GUI ( ), WinMain() ( sapi/cli/php_cli.c, 1198).
main() WinMain() . , , PHP_CLI_WIN32_NO_CONSOLE. sapi/cli/cli_win32.c, Windows GUI.
</Windows>

CGI . main() sapi/cgi/cgi_main.c, 1792.

, FPM main() sapi/fpm/fpm/fpm_main.c, 1570.

Apache2 - (.dll Windows, .so Unix- ). , - ( , / , ..). php_ap2_register_hook() sapi/apache2handler/sapi_apache2.c, 738.
( , Apache Apache documentation.)

php_handler(), HTTP-.

, SAPI ( main(), , -).

:

, PHP script?

php_execute_script() ; php.ini auto_prepend_file auto_append_file, ( , script, ) zend_execute_scripts(), .

php_execute_script() , SAPI CLI zend_execute_scripts().

zend_execute_scripts(), .

PHP ( OP- op_array, , ( op_array NULL), OP- , , , , .

- . zendparse(), Zend/zend_language_parser.c. zendparse() Zend/zend_language_parser.c Git; bison re2c, Zend/zend_language_parser.y Zend/zend_language_scanner.l Zend/zend_language_parser.c.

, , , .

script ( OP-) zend_execute(), Zend/zend_vm_execute.h. , , PHP script.

script (Zend/zend_vm_gen.php) zend_vm_def.h zend_vm_execute.skl zend_vm_execute.h zend_vm_opcodes.h.

zend_vm_def.h , OP-.

, PHP ?

PHP, , - . , ​​PHP, ext/standard, , , ext .

C, PHP, PHP_FUNCTION(). , PHP strpos() ext/standard/string.c, 1948. strchr() strstr() PHP_FALIAS() ext/standard/basic_functions.c 2833.

..

+10

All Articles