Introduction to how PHP is configured at run time

Source: Internet
Author: User
Tags sapi

This article brings you the content of PHP in the runtime configuration of the method introduced, there is a certain reference value, the need for friends can refer to, I hope to help you.

PHP configuration file php.ini is read when PHP is started, and PHP for server module versions is read only once when the Web server is started, while CGI and CLI versions of PHP are read every time. Environment variables can be used in the php.ini file, and variables that already exist in the INI file can be referenced later in PHP5.1. When reading the php.ini file, look for the php.ini file in the following order:

    1. The location specified by the SAPI module (phpinidir directives in apache2, the-C command-line options for CGI and CLI, php_ini parameters in Nsapi, THTTPD environment variables in Php_ini_path, and so on).

    2. The order before the environment variable phprc,php5.2 is after the registry key value.

    3. PHP5.2, in a Windows system, you can set different php.ini file locations for different PHP versions, press [hkey_local_machine\software\php\x.y.z], [hkey_local_machine\ SOFTWARE\PHP\X.Y], [hkey_local_machine\software\php\x], in order to check the registry directory, where x, y, and z represent the major, minor, and release numbers of PHP, respectively. The value of the first IniFilePath found in either directory as the location of the php.ini.

    4. The value IniFilePath in the registry [hkey_local_machine\software\php] in the Windows system.

    5. The current working directory, in addition to the CLI.

    6. The Web server directory in SAPI mode, or the directory where PHP is located under Windows.

    7. The Windows system directory under Windows System (C:\Windows or C:\Winnt), or the location specified by the Compile-time--with-config-file-path option.

If there is a php-<sapi>.ini, it will be used instead of php.ini, where <SAPI> refers to the name of the current SAPI module, such as the CLI, named Php-cli.ini. The name of the SAPI can be obtained through the function php_sapi_name ().

PHP5.3 supports. htaccess-style INI files for each directory, such files can only be processed by cgi/fastcgi SAPI, which invalidates pecl htscanner extension. If you use Apache, you have the same effect with a. htaccess file. In addition to the php.ini file, it will also start from the directory where the PHP files are executed to the Web root directory specified by $_server[' document_root '] to scan the INI file. If the PHP file being executed is outside the Web root directory, only the directory where the PHP file is executed is scanned. Only the INI configuration of the Php_ini_perdir and Php_ini_user modes can be identified in the. User.ini style INI file.

For. User.ini files, there are two configurations to control the use of the INI file:

    1. User_ini.filename: Specifies the INI file name that PHP looks for in the directory, and if it is an empty string, no lookup is made, and the default value is. User.ini.

    2. User_ini.cache_ttl: Specifies the time interval for re-reading the INI file, in seconds, and the default value is 300 (5 minutes).

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.