Home > Backend Development > PHP Tutorial > PHP.INI Configuration File Tour 2_PHP Tutorial

PHP.INI Configuration File Tour 2_PHP Tutorial

WBOY
Release: 2016-07-13 17:28:04
Original
691 people have browsed it

The first part of the article has led you through the structure of the php.ini file and explained how to modify the PHP search path, error handling, and parser related options. The second part will delve 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. Activating extension options There are many different extension options available for PHP. On UNIX systems, extension options need to be created at compile time; for Windows, the binary DLL file will include itself with the PHP distribution. The variable extension_dir contains the name of the directory where PHP should look for relevant extension options. extension_dir = "C:Program FilesInternet ToolsApache inphp4extensions" PHP under Windows includes 20 different extension options, and they are all listed in the php.ini file (via comments). To activate a specific extension option just remove the semicolon from the beginning of the corresponding line and restart the server. If you want to disable an extended option (for example, if you need to improve system performance), just add the semicolon again at the beginning of the line. If the extension options are not listed in the php.ini file, you can use the variable extension and pass the corresponding DLL file name to this variable. extension=php_domxml.dll extension=php_dbase.dll Set extension-specific variables The extension-specific variables are stored in a separate area in the configuration file. For example, all variables related to MySQL extensions should be stored in the [MySQL] area of ​​php.ini. If you need to use PHP's mail() function, you need to set the following three variables. When sending email messages through the PHP mail() function, you need to use SMTP and the variable sendmail_from (Windows systems) or the variable sendmail_path (UNIX systems). For Windows, these variables set the SMTP server used and the "From:" address displayed in the email message; while for UNIX, the variable sendmail_path sets the path of the MTA (mail transfer agent) for mail transfer. . SMTP = myserver.localnet.com sendmail_from = me@localhost.com sendmail_path = /usr/sbin/sendmail The variables java.class.path, java.home, java.library and java.library.path are all used to set the search for Java classes and The path to the library. These values ​​will be used by Java extensions, so if you want PHP to integrate correctly with Java programs, you must ensure that these variables are set correctly. java.class.path = .php_java.jar java.home = c:jdk java.library = c:jdkjre inhotspotjvm.dll java.library.path= . The variable session.save_path specifies the temporary directory required to save session information. Normally, this directory defaults to /tmp, but since this default directory does not exist on Windows systems, you must reset it to the correct Windows temporary directory, otherwise the session handler will call the session_start() function Annoying error messages pop up. At the same time, the validity period of the session cookie can be controlled through the variable session.cookie_lifetime. session.save_path = c:windows emp session.cookie_lifetime = 1800 Security settings In php.ini, there are many variables related to security issues of PHP installation. The most interesting one is the safe_mode variable, which is recommended to be set for ISPs and shared-hosting services. This variable will limit the user's use of PHP. safe_mode = Off When safe mode is turned on, you can specify the directory to search for related files through the variable safe_mode_include_dir. By placing the binary program in a specific directory and telling PHP the directory using the safe_mode_include_dir variable, PHP will limit the kinds of programs that can use the exec() command to run PHP scripts. Only binary files in this directory can be accessed through the exec() command. safe_mode_include_dir = /usr/local/lib/php/safe-include safe_mode_exec_dir = /usr/local/lib/php/safe-bin You can also limit file operations through the variable open_basedir. This variable will set the directory name as the root for file operations. After this variable is set, files stored outside this directory tree will not be accessible to PHP. This is a great way to restrict users to their home or web directories on a shared system. open_basedir = /home/web/ The variable max_execution_time sets the time that PHP waits for the script to complete before forcibly terminating the script. This time is calculated in seconds. This variable is useful when the script enters an infinite loop. However, this feature can also cause the operation to fail when there is a legitimate activity that takes a long time to complete (such as uploading a large file). In such cases, you must consider increasing the value of this variable to prevent PHP from shutting down the script while it is executing some important process. max_execution_time = 90 We just mentioned uploading, now let’s take a look at how to configure the uploads variable and form variable. Configuring file uploads and form variables If the security strength provided by the security configuration we discussed earlier in the article does not meet your requirements, you can further improve the security strength by turning off file uploads or setting a maximum file size limit for each upload. The above two functions will be implemented through the variables file_uploads and upload_max_filesize respectively.Generally speaking, unless your system has an application designed to receive files (such as a photo album based on a Web FTP service), you should set a relatively small file size limit. file_uploads = On upload_max_filesize = 2M If you don't care about uploading files, but use a lot of forms in your PHP application, here are two variables that will be of great interest to you. The first is the variable register_globals, which solves a long-standing pain point for PHP developers. In PHP 3.x, this variable defaults to On. This way the form variables will be automatically converted into PHP variables when the form is submitted. In PHP 4.x, this variable is set to Off by default for security reasons. As a result, form variables will only be accessed through specific $_GET and $_POST. This also caused many scripts written in PHP 3.x to have runtime problems, requiring developers to rewrite the scripts and retest them. For example, the value entered into the form field will be understood as $email for a PHP 3.x script; but will be interpreted as $_POST[email] or $_GET[email] for a PHP 4.x script. Normally, this variable can be set to Off, which can provide more secure protection against script attacks through forms. If compatibility with earlier PHP 3.x scripts needs to be considered, it should be set to On. register_globals = Off A variable related to form submission is post_max_size, which will control the maximum amount of data that PHP can receive in a form submission using the POST method. It seems unlikely that the default 8 MB will need to be changed to a larger size. Instead, it should be appropriately reduced to a more realistic value. But if you want to use the PHP file upload function, you need to change this value to be larger than upload_max_filesize. post_max_size = 8M The max_input_time variable was added in PHP 5. This variable can limit the time in seconds for receiving data through POST, GET and PUT methods. If your application is running on a slow link, you may need to increase this value to accommodate the additional time required to receive data. max_input_time = 90 Performance Tuning You can also improve the performance of the PHP parser by adjusting some variable values. To avoid running scripts from using up a lot of available system memory, PHP allows you to define memory usage limits. Use the memory_limit variable to specify the maximum memory capacity that a single script can use: memory_limit = 8M The value of the variable memory_limit should be appropriately larger than the value of post_max_size. Another method that can be used to improve performance is to disable the variables $argc and $argv, which are used to store the number of arguments passed to the application on the command line and the actual argument values. register_argc_argv = false Similarly, you can also disable $HTTP_GET_VARS and $HTTP_POST_VARS, because you are unlikely to use the first two methods today when $_GET and $_POST are used. Disabling this feature can bring performance improvements, but this is only possible through the variable register_long_arrays in PHP 5. register_long_arrays = false function ini_set() Finally, you need to pay attention to the ini_set() function. When PHP reads all the setting information in the php.ini configuration file, it also provides the function of using the ini_set() function to change these settings according to the per-script principle. This function receives two parameters: the name of the configuration variable that needs to be adjusted, and the new value of the variable. For example, to increase the maximum execution time when a script appears: Such a setting will only affect the script being set. Once the script has finished executing, the variable will automatically be restored to its original value. If the PHP application is running on a shared server, you are unlikely to have access to the main php.ini configuration file. At this time, the function ini_set() can allow dynamic modification of the PHP configuration according to special requirements, which will bring you great convenience.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531810.htmlTechArticleThe first part of the article has led you through the structure of the php.ini file and explained how to modify the PHP search path, Error handling, and parser related options. The second part will go deep into the configuration...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template