PHP Kernel--source installation and introduction ____php

Source: Internet
Author: User
Tags function definition html tags pear php compiler php download svn zend git clone

Get PHP sourceIn order to learn the implementation of PHP, first need to download the PHP source code. Download source is preferred to go to the official PHP website http://php.net/downloads.php download, if you like to use Svn/git and other version control software, you can also use Svn/git to obtain the latest source code.
# git official address
git clone https://git.php.net/repository/php-src.git
# can also access GitHub official mirrors
git clone git:// Github.com/php/php-src.git
cd php-src && git checkout PHP-5.3 
# Check out 5.3 branches


PHP Source directory structureThe saying goes: There is no front for a heavy sabre. PHP's source code is very clear in structure. Here is a brief description of the PHP source directory structure. Root directory:/This directory contains a lot of things, mainly contains some documentation and design. In fact, these README files in the project are well worth reading for example:/readme. Php4-to-php5-thin-changes This document details some of the differences between PHP4 and PHP5. There is also a more important file/coding_standards, if you want to write PHP extensions, this file must read, regardless of your personal code style, how to use indentation and braces, since came to such a group should adapt to such norms, It will be easier to read your code or someone else's reading your code. Build, as the name suggests, here are some of the source code compiled related to some files, such as the beginning of the construction of the buildconf script and other files, and some check the environment of the script. Ext official extensions directory, including the vast majority of PHP function definition and implementation, such as array series, PDO series, SPL series, such as the implementation of functions, are in this directory. Individual writing extensions can also be put into this directory when testing to facilitate testing and debugging. Main store Here is the core of PHP files, the main implementation of PHP infrastructure, here and Zend Engine, Zend engine mainly to achieve the language of the most core language operating environment. The implementation directory of Zend Zend engine, such as lexical parsing of scripts, implementation of opcode and implementation of extension mechanism, etc. Pear, "PHP extension and Application Warehouse," contains the core files of pear. SAPI contains a variety of server abstraction layers of code, such as Apache mod_php,cgi,fastcgi and FPM, and so on. TSRM PHP's thread safety is built on the TSRM library, and the common *g macros in PHP implementations are typically the encapsulation of TSRM, TSRM (thread safe Resource Manager) Threading Security Resource Manager. Tests PHP's test script collection, including the PHP features of the test files Win32 This directory mainly includes some of the Windows platform-related implementation, such as SOKCET implementation in Windows and *nix platform is not the same, It also includes scripts related to compiling PHP under Windows.

global variable macros in PHPSome of the most common macros that are often seen in PHP's source code, or some that are more difficult to understand than those who start contacting the source. These code in the PHP source of the frequency is very high, basic in each module will have their figure.
In PHP code, you can often see functions like PG (), EG (), which are all macros defined in PHP, and the main function of this series is to solve the global variable package macros written by thread safety, such as $php_src/main/php_ The Globals.h file contains a number of macros in this category. For example, pg this PHP's core global variable macros. This is defined by the code shown below.
#ifdef ZTS   //compile-time thread safety is used thread Safety Library
# define PG (v) tsrmg (core_globals_id, php_core_globals *, v)
extern Phpapi int core_globals_id;
#else
# define PG (v) (CORE_GLOBALS.V)//Otherwise this is actually an ordinary global variable
extern zend_api struct _php_core_globals core_globals ;
#endif

As above, Zts is a thread-safe tag, which is described in more detail in later chapters, and is not explained here. The following is a brief example of the global parameters of PHP runtime, this global variable is a structure like the following, the meaning of each field, such as the comment after the field:
struct _php_core_globals {zend_bool MAGIC_QUOTES_GPC.//Whether to use automatic string escape for the entered Get/post/cookie data. Zend_bool Magic_quotes_runtime;  Whether to use automatic string escape Zend_bool magic_quotes_sybase for data generated from external resources at run time;    Whether to use Sybase form of automatic string escape Zend_bool safe_mode;   Whether to enable Safe mode Zend_bool allow_call_time_pass_reference;   Whether to force arguments to be passed by reference when a function is called Zend_bool Implicit_flush;  Whether the PHP output layer is required to automatically refresh data after each output block long output_buffering;    Output buffer size (bytes) char *safe_mode_include_dir;
        In Safe mode, the Uid/gid check is skipped when the group directory and the files under its subdirectories are included.    Zend_bool Safe_mode_gid;
        In Safe mode, the default is to do a UID comparison check zend_bool Sql_safe_mode when accessing files;    Zend_bool Enable_dl; Whether the DL () function is allowed.
 
        The DL () function is only available when installing PHP as an Apache module.   Char *output_handler;
 
        Redirects the output of all scripts to an output handler function.    Char *unserialize_callback_func;   If the solution serialization processor needs to instantiate an undefined class, the callback function specified here will be invoked with the name of the undefined class as an argument by Unserialize (), long serialize_precision;
 
        The precision (number of significant digits) when the floating-point and the double-precision data are serialized for storage.   Char *safe_mode_exec_dir; //In safe mode, only the executable program under that directory allows the execution of functions performed by the system program.  Long Memory_limit;
        The maximum number of bytes of memory a script can request (use K and M as units).    Long Max_input_time;
 
        Each script resolves the maximum allowable time (in seconds) for input data (POST, get, upload). Zend_bool track_errors;
        Whether to save the most recent error or warning message in the variable $php_errormsg.   Zend_bool display_errors;
        Whether to display the error message as part of the output.   Zend_bool display_startup_errors;
        Whether to show PHP startup errors.   Zend_bool log_errors;   Whether the error is recorded in the log file, and where it is recorded depends on the error_log instruction long Log_errors_max_len;
        Sets the maximum length of the error source associated with the error message that is attached to the error log.   Zend_bool ignore_repeated_errors;
        Whether to ignore duplicate error messages when logging the error log.   Zend_bool Ignore_repeated_source;
        Whether duplicate error sources are ignored when repeating error messages are ignored.  Zend_bool Report_memleaks;
        Whether to report a memory leak.    Char *error_log;
 
        The file to which the error log is logged. Char *doc_root;
        The "root directory" of PHP. Char *user_dir; Tell PHP which directory to find Char *include_path when using/~username to open the script;
        Specifies a set of directories for require (), include (), Fopen_with_path () function to find files. Char *open_basedir;
        Restrict all files (including the file itself) that PHP allows to operate under this Group directory list. char *Extension_dir;
 
        A directory of Extension libraries (modules) that PHP uses to find dynamic extension modules.   Char *upload_tmp_dir;   Temporary directory for files when uploading files long upload_max_filesize;
 
        Maximum size of files allowed to be uploaded.  Char *error_append_string; The string char *error_prepend_string for the output after the error message;    The string char *auto_prepend_file for the output before the error message;
        Specifies the name of the file that is automatically resolved before the primary file. Char *auto_append_file;
 
        Specifies the name of the file that is automatically parsed after the primary file.   Arg_separators Arg_separator;
 
        The delimiter in the URL that PHP produces to separate the arguments.  Char *variables_order;
 
        PHP registers the order of environment, GET, POST, Cookie, Server variables.  HashTable Rfc1867_protected_variables;    RFC1867 protected variable name, useful in main/rfc1867.c file to this variable short connection_status;    Connection state, there are three states, normal, interrupted, timeout short ignore_user_abort;
 
        Whether to persist in completing the entire request even after the user aborts the request. unsigned char header_is_being_sent;  Whether the header information is being sent zend_llist tick_functions;
 
        Useful in PHP_TICKS.C files in the main directory only, the functions defined here are useful in functions such as register_tick_function.  Zval *http_globals[6]; Store information such as GET, POST, server Zend_bool expose_php; Whether to show PHP information Zend_bool register_globals;
        Whether to register E, G, P, C, S variables as global variables. Zend_bool register_long_arrays;
        Whether to enable legacy long arrays (http_*_vars).   Zend_bool register_argc_argv;
        Whether to declare $ARGV and $ARGC global variables (containing information using the Get method). Zend_bool Auto_globals_jit;
 
        Whether it is created only when the $_server and $_env variables are used (not automatically when the script is started).   Zend_bool y2k_compliance;
 
        Whether to force the 2000 adaptation (may cause problems in a Y2K-adapted browser).  Char *docref_root;   If the html_errors command is turned on, PHP will display a hyperlink on the error message, Char *docref_ext;
 
        Specifies the file name extension (must contain '. ').  Zend_bool html_errors;
        Whether to use HTML tags in error messages.   
 
        Zend_bool xmlrpc_errors;
 
        Long Xmlrpc_error_number;
 
        Zend_bool Activated_auto_globals[8];    Zend_bool modules_activated; Whether the module Zend_bool file_uploads has been activated;
        Whether to allow HTTP file uploads.   Zend_bool During_request_startup;  Whether to Zend_bool Allow_url_fopen during the initialization of the request;    Whether to allow remote files to be opened Zend_bool Always_populate_raw_post_data; Whether to always generate $http_raw_post_data variables (original POST data)。    Zend_bool Report_zend_debug;
 
        Whether to turn on Zend Debug, only used in MAIN/MAIN.C files.    int last_error_type;   The last error type char *last_error_message;  The last error message char *last_error_file; The last error file int last_error_lineno;    The last error line char *disable_functions;
        The directive accepts a comma-delimited list of function names to disable specific functions.  Char *disable_classes;
        The directive accepts a comma-delimited list of class names to disable a particular class.    Zend_bool Allow_url_include;
        Whether to allow Include/require remote files.  Zend_bool exit_on_timeout;
Timeout is exited #ifdef php_win32 zend_bool com_initialized;   #endif long Max_input_nesting_level;  The largest number of nesting layers zend_bool in_user_include;    Whether the user contains space char *user_ini_filename;    The user's INI filename is long user_ini_cache_ttl;    INI cache expiration limit char *request_order;    Priority is higher than variables_order, when the request variable is generated, the individual feels that it is the legacy of history Zend_bool Mail_x_header;
 
        Used only in ext/standard/mail.c files, char *mail_log;
Zend_bool In_error_log; };
A large portion of the above field corresponds to a configuration item in the php.ini file. These fields are assigned when PHP starts and reads the php.ini file, and some configurations of the Ini_get () and Ini_set () functions of the user space operate on the global variable. There are a lot of similar macros in other parts of the PHP code, these macros, like the PG macros, are designed to encapsulate thread safety and, at the same time, indicate that this is global by the agreed G name, which is generally abbreviated because these global variables are used everywhere in the code, which reduces keyboard input. We should all be as lazy as possible, aren't we? If you've read some PHP extensions and you should have seen similar macros, it's also a code specification, and it's best to name and package the global variables when writing extensions, because we can't make any assumptions about the user's PHP compiler conditions.



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.