Home > Article > Backend Development > Why does php cause a 502 error?
The reasons for the 502 error in php are: 1. The memory_limit of php.ini is too small; 2. The setting of max_children or max_requests in php-fpm.conf is unreasonable; 3. The execution time of the php program is too long and times out.
The common reasons are as follows:
1. The memory_limit of php.ini is too small (if there are individual php program processes that need to occupy This must be noted when the memory is very large);
2. The setting of max_children or max_requests in php-fpm.conf is unreasonable;
If the setting is too small, there will not be enough cgi processes to process the request. If it is too large, there will be a situation where the response is normal for a while, and then it takes a long time for a response.
3. Check the nginx error log and find that pstream sent too big header while reading response headerfrom upstream. Then check whether the client head buffer and fastcgi buffer size are too small and can be set to 32K;
4 . The execution time of the php program is too long and times out. Check the various timeout settings in nginx and fastcgi;
5. php-fpm has a parameter max_requests, which specifies the maximum number of requests each child can handle. will be closed;
Under a large number of processing requests, if this value is set too small, it will cause frequent suicide and creation of children, which wastes a lot of time. If all children almost commit suicide at this time, they will be reset before rebuilding. No children responded to the request, so 502 appeared. You can set this value larger or 0 [infinite].
If you want to know more related knowledge, please visit php Chinese website.
The above is the detailed content of Why does php cause a 502 error?. For more information, please follow other related articles on the PHP Chinese website!