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

PHP.INI Configuration File Tour 2_PHP Tutorial

Jul 13, 2016 pm 05:28 PM
php.ini document article roaming of structure Configuration file

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to recover expired WeChat files? Can expired WeChat files be recovered? How to recover expired WeChat files? Can expired WeChat files be recovered? Feb 22, 2024 pm 02:46 PM

Open WeChat, select Settings in Me, select General and then select Storage Space, select Management in Storage Space, select the conversation in which you want to restore files and select the exclamation mark icon. Tutorial Applicable Model: iPhone13 System: iOS15.3 Version: WeChat 8.0.24 Analysis 1 First open WeChat and click the Settings option on the My page. 2 Then find and click General Options on the settings page. 3Then click Storage Space on the general page. 4 Next, click Manage on the storage space page. 5Finally, select the conversation in which you want to recover files and click the exclamation mark icon on the right. Supplement: WeChat files generally expire in a few days. If the file received by WeChat has not been clicked, the WeChat system will clear it after 72 hours. If the WeChat file has been viewed,

Can Tmp format files be deleted? Can Tmp format files be deleted? Feb 24, 2024 pm 04:33 PM

Tmp format files are a temporary file format usually generated by a computer system or program during execution. The purpose of these files is to store temporary data to help the program run properly or improve performance. Once the program execution is completed or the computer is restarted, these tmp files are often no longer necessary. Therefore, for Tmp format files, they are essentially deletable. Moreover, deleting these tmp files can free up hard disk space and ensure the normal operation of the computer. However, before deleting Tmp format files, we need to

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

Different uses of slashes and backslashes in file paths Different uses of slashes and backslashes in file paths Feb 26, 2024 pm 04:36 PM

A file path is a string used by the operating system to identify and locate a file or folder. In file paths, there are two common symbols separating paths, namely forward slash (/) and backslash (). These two symbols have different uses and meanings in different operating systems. The forward slash (/) is a commonly used path separator in Unix and Linux systems. On these systems, file paths start from the root directory (/) and are separated by forward slashes between each directory. For example, the path /home/user/Docume

How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? Mar 14, 2024 pm 02:07 PM

Quark Netdisk and Baidu Netdisk are currently the most commonly used Netdisk software for storing files. If you want to save the files in Quark Netdisk to Baidu Netdisk, how do you do it? In this issue, the editor has compiled the tutorial steps for transferring files from Quark Network Disk computer to Baidu Network Disk. Let’s take a look at how to operate it. How to save Quark network disk files to Baidu network disk? To transfer files from Quark Network Disk to Baidu Network Disk, you first need to download the required files from Quark Network Disk, then select the target folder in the Baidu Network Disk client and open it. Then, drag and drop the files downloaded from Quark Cloud Disk into the folder opened by the Baidu Cloud Disk client, or use the upload function to add the files to Baidu Cloud Disk. Make sure to check whether the file was successfully transferred in Baidu Cloud Disk after the upload is completed. That's it

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

What is hiberfil.sys file? Can hiberfil.sys be deleted? What is hiberfil.sys file? Can hiberfil.sys be deleted? Mar 15, 2024 am 09:49 AM

Recently, many netizens have asked the editor, what is the file hiberfil.sys? Can hiberfil.sys take up a lot of C drive space and be deleted? The editor can tell you that the hiberfil.sys file can be deleted. Let’s take a look at the details below. hiberfil.sys is a hidden file in the Windows system and also a system hibernation file. It is usually stored in the root directory of the C drive, and its size is equivalent to the size of the system's installed memory. This file is used when the computer is hibernated and contains the memory data of the current system so that it can be quickly restored to the previous state during recovery. Since its size is equal to the memory capacity, it may take up a larger amount of hard drive space. hiber

Detailed explanation of the role of .ibd files in MySQL and related precautions Detailed explanation of the role of .ibd files in MySQL and related precautions Mar 15, 2024 am 08:00 AM

Detailed explanation of the role of .ibd files in MySQL and related precautions MySQL is a popular relational database management system, and the data in the database is stored in different files. Among them, the .ibd file is a data file in the InnoDB storage engine, used to store data and indexes in tables. This article will provide a detailed analysis of the role of the .ibd file in MySQL and provide relevant code examples to help readers better understand. 1. The role of .ibd files: storing data: .ibd files are InnoDB storage

See all articles