Home >Backend Development >PHP Tutorial >Configuration of php.ini and efficiency of CMS program Optimizing Configuration Short Story_PHP Tutorial
Developers who have worked on CMS all know that background login and file uploading in a LAMP environment are two places where problems can easily occur, and most of them are due to PHP configuration problems, so it is crucial to optimize PHP. For the optimization of PHP, it is mainly to reasonably adjust and set the relevant main parameters in php.ini. Let's take a look at how to set some parameters in php.ini that have a greater impact on performance (the system is CentOS).
(1) PHP function disabled found
Disable_functions =
This option can set which PHP functions are prohibited from use. Some functions in PHP are quite risky. You can directly execute some CentOS system-level script commands. If these functions are allowed to be executed, when a vulnerability occurs in the PHP program , the loss is very serious! Below we give the recommended disabled function settings:
Disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status
Note: If your server contains some PHP programs for CentOS system status detection, do not disable shell_exec, proc_open, proc_get_status and other functions.
(2) PHP script execution time found
max_execution_time = 30
This option sets the maximum execution time of the PHP program. If a PHP script is requested and the PHP script fails to be executed within the max_execution_time, PHP will no longer continue execution and directly return a timeout error to the client. If there is no special need, this option can be kept at the default setting of 30 seconds. If your PHP script really requires a long execution time, you can increase the time setting appropriately.
(3) PHP script processing memory usage found
Memory_limit = 8M
This option specifies the maximum memory that PHP script processing can occupy. The default is 8MB. If your server memory is more than 1GB, this option can be set to 12MB to obtain faster PHP script processing efficiency.
(4) PHP global function declaration found
register_globals = Off
Many articles on PHP settings on the Internet recommend setting this option to On. In fact, this is an extremely dangerous setting method and may cause serious security issues. If there are no special needs, it is highly recommended to keep the default settings!
(5) PHP upload file size limit found
upload_max_filesize = 2M
This option sets the maximum upload file size allowed by PHP. The default is 2MB. This setting can be appropriately increased according to actual application requirements.
(6) Session storage medium found
session.save_path
If your PHP program uses Session dialogue, you can set the Session storage location to /dev/shm. /dev/shm is a unique TMPFS file system of Linux system. It is a file system that uses memory as the main storage method. It is better than RAMDISK because DISKSWAP can be used as a supplement, and it is a function module that comes with the CentOS system and does not need to be configured separately. Think about it, how much faster will it be from disk IO operations to memory operations? Just note that all data stored in /dev/shm will be lost after the server is restarted. But this is insignificant for Session. In this way, we have completed the steps of PHP optimization on CentOS system.