PHP. INI configuration file roaming

Source: Internet
Author: User
Tags php server
Before you start to browse the PHP configuration file, it is worth noting that the internal structure of the PHP configuration file. This file is called php. ini. it has the same structure as the ini files widely used in many Windows applications. Php. ini is an ASCLL text file, which is divided into multiple parts, each part includes related parameters, as shown below: [MySection] variab PHP configuration file

Before browsing the PHP configuration file, it is worth noting that the internal structure of the PHP configuration file is structured. This file is called php. ini. it has the same structure as the ini files widely used in many Windows applications. Php. ini is an ASCLL text file, which is divided into multiple parts, each part includes related parameters, as shown below:

[MySection]
Variable = "value"
Anothervariable = "anothervalue

The name of each part is placed in square brackets at the beginning, followed by the name pair number, each name pair occupies a separate line. Because PHP code is used with rules, the parameter name is very sensitive and cannot contain spaces. However, the parameter value can be a number, string, or Boolean logical number.

The semicolon is at the beginning of each row and serves as the specified tag. This makes it easy to use or avoid using these features of PHP, without deleting the row. you can annotate it, so that this row will not be compiled. If you want to use this feature again in the database in the future, it is very convenient and you do not need to delete it from the file.

For PHP recognition. the INI file must be placed in the current directory, which is defined in the $ PHPRC environment parameter or the directory specified during the compilation time (for Windows PHP, it is the first Windows directory ).

After changing the php format through the PHP. ini file, you will need to restart the Web server to make your change take effect (of course, this is assumed that you are using PHP through the Web server ). For PHP command lines, the configuration file is read once every time a PHP binary program is imported.

  Set parser options

In this process, the first step is the most important step, that is, the options related to the language interpreter. The first option here is the engine parameter, which controls the PHP server to "On" or "Off ". If the server is disabled, the embedded PHP code will not be parsed by the Web server. However, the server is usually "On.

Engine = On

  Short_open_tagParameter control whether the syntax analyzer recognizes shortcuts , Similar to the identification standard key . If this parameter conflicts with other languages, or you want to use strict syntax rules in PHP code, disable this parameter.

Short_open_tag = On

Generally, Cookie or HTTP data must be sent before any program generates output. If you cannot implement this in a program, you can use the output_buffering parameter to make the PHP call to the output buffer take effect.

When the output buffer is in the "On" status, PHP stores the program output in a dedicated memory buffer and sends the data within a specified time range. This allows you to send special HIIP titles and important data during the programming process or when it is about to end. However, it also reduces some important functions.

Output_buffering = Off

  

You can also specify the buffer size through the output_buffering parameter value, for example:

Output_buffering = 2048

  

When PHP is started, it adds information about the version number to the standard title box of the Web server. To disable this feature, set expose_php to false. This is very useful. for example, you can prevent hackers from hiding your webpage server capacity.

Expose_php = On

  

Now let's take a look at how to set the search path and capture errors.

  Set PHP search path

You can use the include_path parameter to set the PHP search path, which can receive directories of the series. When PHP encounters a file prompt with no path, it will automatically detect these directories.

If you frequently use function libraries or classes, you can list their current locations to simplify file search. This is also a good way to add paths to the PEAR directory of PHP. the PEAR directory contains many reusable classes.

Export de_path = ".:/usr/local/lib/php/pear :"

  

Window users can use semicolons to specify multiple locations, while UNIX users must be separated by colons.

The best two parameters for this section are auto_prepend_file and auto_append_file. These parameters specify some files that automatically set the search path for the data files when PHP starts and ends. This feature is mostly used to set the title and the search path of the page in PHP running, which allows you to save several lines of code in each PHP file. However, the specified file will be added to the * all * PHP document. Therefore, these parameters are best suited to the server of a single program.

These files can be PHP programs or HTML files. Embedded PHP code must use standard

Auto_prepend_file =/home/web/uplodes/header. php
Auto_append_file =/home/web/uplodes/legal. php

  

  Capture error

PHP errors are divided into four types: analysis errors, code error notifications (such as non-initialization parameters), warnings (not very serious errors), and severe errors. In general, PHP displays an error when it encounters an analysis error, a common error, or a very fatal error. If the error is very serious, it may stop processing the program. You can use the error_reporting parameter to change this feature. this parameter can identify some error code and display the program code corresponding to the error.

Error_reporting = E_ALL

  

To disable error display, set display_errors to false. Conversely, you can set the log_errors parameter to write error messages to error logs.

From the security perspective, disabling error display is advantageous. Hiding detailed information of the system prevents malicious users from opening and destroying your web pages or programs. You should specify a file name for these errors by setting the error_log parameter and write the errors in a custom log file or by specifying the specific parameter "syslog. Remember, you should check these log files regularly to view the changes in the log files.

Display_errors = Off
Log_errors = On
Error_log = "error. log"

  

In the second part of this article, I will go further to php. the INI file discusses the following settings, including: file upload, table parsing, running PHP in Restricted Mode for better security, stimulating scalability, and setting the memory usage of resources, and make some features ineffective to improve performance.

The first part of this article has introduced the structure of the php. ini file and explained how to modify the PHP search path, handle errors, and related options of the parser. The second part will go deep into the configuration file, including how to activate PHP extension options, set resource limits for PHP scripts, and dynamically change configuration variables through PHP scripts.

Related Article

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.