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

The solution of stopping php-cgi under linux

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you the "solution to stop php-cgi under linux", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the solution to stop php-cgi under linux.

The solution to stop php-cgi under linux is to change the configuration item of nginx, reduce the number of requests for FastCGI, and keep the buffers unchanged as far as possible, such as [fastcgi_buffer_size 128k;].

This article operating environment: linux 5.9.8, php 7, thinkpad T480 computer.

Foreword:

Stumbled upon a server in production (centos 5.264-bit 4G memory) always had the problem that the website could not be opened. Later, I went to the server and found that both nginx and php-cgi were running, but at this time the cpu of php-cgi was 0. So I immediately looked at the file handle limit:

Ulimit-n

The result is 1024, which is too small for services in production.

Most of the solutions given on the Internet are input directly.

Ulimit-SHn 51200 # 51200 can be adjusted according to the application

The disadvantage of this method is obvious, once you log out, the setting will be invalid.

It is also said that those who wrote the command directly into / etc/rc.d/rc.local found a correct way to do it today.

Open / etc/security/limits.conf, with detailed comments, find the following settings (insert if not)

The code is as follows

* soft nofile 51200 * hard nofile 51200

Log in again after exit and check the number of handles, which has been correctly set to 51200.

If you encounter a similar situation, you can check to see if it is caused by a small number of file handles.

A solution to 502 Bad Gateway appears when visiting

Nginx 502Bad Gateway means that the requested php-cgi has been executed, but the php-cgi process is terminated due to some reason (usually the problem of reading resources) that the execution is not finished. Generally speaking, websites with too many concurrency are prone to this error. There are many reasons for 502 Bad Gateway, but most people can solve it by modifying the following parameters.

Change several configuration items of nginx to reduce the number of FastCGI requests and keep buffers unchanged as far as possible:

The code is as follows

Fastcgi_buffer_size 128k fastcgifted buffers 2 256k fastcgifted busyweights buffers size 256k fastcgifted temptpacks fileholders writecake size 256k

Open the / usr/local/php/etc/php-fpm.conf file and modify the following parameters:

The code is as follows

25requests "> 20486553530s60s

Request_terminate_timeout refers to the time it takes fast-cgi to execute the script, which defaults to 0s. 0s means to keep the php-cgi running without a time limit. If you set it to 0s here, then when 502 Bad Gateway appears, the state of 502 will last forever. But if you set it to 5s, it will recover automatically when php-cgi dies for 5s. This value can be set according to the performance of your server. Here I set it to 60s.

Max_children represents the processing process of the php-cgi. If the max_children setting is small, such as 5-10, then the php-cgi will be "very tired", the processing speed will be slow, and the waiting time will be longer. A 504 Gateway Time-out error will occur if the request has not been processed for a long time. Setting max_children also needs to be set according to the performance of the server. If you increase the number of processes, the memory footprint will increase accordingly. Normally, the memory consumed by each php-cgi is about 20m. Here I set it to 25.

The default static processing mode of php-fpm will cause the process of php-cgi to occupy memory for a long time and cannot be released, which is also one of the reasons for nginx errors, so you can change the processing mode of php-fpm to apache-like mode.

Complete the modification and execute lu-restart (LuManager server management system).

The above is all the contents of this article entitled "the solution to stop php-cgi under linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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