Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to optimize the configuration performance of PHP.ini

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I will talk to you about how to tune the configuration performance of PHP.ini, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

The default installation of PHP is like an ordinary suit bought in a department store. It fits, but it's not perfect. The tuned PHP is like a custom suit that matches your size exactly. It is important to note, however, that tuning PHP is only a move to improve PHP performance and efficiency, and there is nothing you can do about poor code and unresponsive API calls.

Php.ini file

The PHP interpreter is configured and tuned in the php.ini file, which has different locations in different operating systems, and the general command line corresponding php.ini and PHP-FPM corresponding php.ini files are separate. Here we assume that the php.ini corresponding to PHP-FPM is configured, but the optimization measures described below apply to all php.ini.

Memory

When running PHP, you need to care about how much memory each PHP process uses, and the memory_limit setting in php.ini is used to set the maximum amount of system memory that a single PHP process can use.

The default value for this setting is 128m, which may be appropriate for most small and medium-sized PHP applications, but if you are running mini PHP applications, you can lower this value to save system resources, and vice versa, if you are running memory-intensive PHP applications, you can increase this value. The size of this value is determined by the available system memory, and it is an art to determine how much value is allocated to PHP, how much memory is allocated to PHP, and how many PHP-FPM processes you can afford.

File upload

If your application allows files to be uploaded, it is best to set the maximum file size that can be uploaded. In addition, it is best to set the maximum number of files that can be uploaded at the same time:

By default, PHP allows 20 files to be uploaded in a single request, and the maximum number of files to be uploaded is 2MB. Here, I set a maximum of 3 files to be uploaded in a single request, and the maximum for each file is 10MB. This value should not be set too high, otherwise a timeout will occur.

Handle a session

PHP's default session handler slows down large applications because it stores session data on the hard disk and wastes time by creating unnecessary disks. We should keep the session data in memory, for example, using Memcached or Redis. This has the added benefit of being easy to scale in the future. If the session data is stored in the hard disk, it is not convenient to add additional servers. If the session data is stored in Memcached or Redis, any distributed PHP-FPM server can access the session data.

After reading the above, do you have any further understanding of how to tune the configuration performance of PHP.ini? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report