search
HomeBackend DevelopmentPHP ProblemWhat is the problem with php502?

What is the problem with php502?

Oct 17, 2019 pm 03:38 PM
php

What is the problem with php502?

The reason why the server appears 502 is that the connection has timed out. We sent a request to the server. Because the server currently has too many connections, the server cannot give a normal response, resulting in such an error.

So if your server has a very large concurrency, you can only add more machines first, and then optimize in the following ways to achieve better results; but if you have a small concurrency but get 502, it can generally be attributed to a configuration problem. , script timeout problem.

1. The number of php-fpm processes is not enough

Use netstat -napo | grep "php-fpm" | wc -l to check the current number of fastcgi processes. If the number is close to the upper limit configured in conf, you need to increase the number of processes.

But you can’t increase it endlessly. You can adjust the number of php-fpm sub-processes to 100 or more according to the server memory. On a server with 4G memory, 200 is enough.

2. Increase the number of files opened by the Linux kernel

You can use these commands (must be the root account)

echo 'ulimit -HSn 65536'>> /etc/profile
echo 'ulimit -HSn 65536'>> /etc/rc.local
source /etc/profile

3. Script execution time timeout

If the script waits for a long time without returning for some reason, resulting in new requests not being processed, you can appropriately adjust the following configuration.

nginx.conf The main contents are as follows:

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

php-fpm.conf If the contents are as follows:

request_terminate_timeout =10s

4. The cache setting is relatively small

Modify or add configuration to nginx.conf

proxy_buffer_size 64k;
proxy_buffers  512k;
proxy_busy_buffers_size 128k;

Recommended tutorial: PHP video tutorial

The above is the detailed content of What is the problem with php502?. For more information, please follow other related articles on the PHP Chinese website!

Statement
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 Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool