About the first timeout error you see, if you are using a FastCGI configuration, then you might need to review this:
fastcgi_read_timeout 600s;
Make sure that value is longer than the longest processing PHP will be doing.
You should also definitely increase worker connections setting to whatever expected number of simultaneous connections you expect (say 10000):
worker_connections 10000;
Also, as mentioned by Sang Lu's answer, you need to make sure nginx can open enough file handles (which includes network sockets as well).
If you start the master nginx process as root, you can simply do (at least two times of theworker_connections
configuration above:
worker_rlimit_nofile 21000;
The other way is to useulimit
or/etc/security/limits.conf
for the user that starts the master nginx process.
Probably it is that your Nginx process is opening too many files. You can increase this limit by following this article: How to Increase Number of Open Files Limit in Linux
To change this setting, you need the root privilege and do as follows:
Open the /etc/security/limits.conf file:vi /etc/security/limits.conf
Append those lines at the end of the file:
## Example hard limit for maximum number of opened files
* hard nofile 10240
## Example soft limit for maximum number of opened files
* soft nofile 10240
Save all changes and Reboot your Server/VPS to apply new settings.
Note: The number 10240 is the maximum number of files that a process can open. Change this value as your needs.
Here are a few steps you can take to diagnose and resolve the issue:
Increasing PHP-FPM timeouts requires changing therequest_terminate_timeout
,request_slowlog_timeout, and
max_execution_timesettings in your PHP-FPM configuration file (often located at
/etc/php-fpm.confor
/etc/php/version/fpm/php-fpm.conf)`. Once the changes have been made, restart PHP-FPM.
Increase Nginx timeouts: In your Nginx configuration file (usually located at/etc/nginx/nginx.conf
or/etc/nginx/conf.d/default.conf
), adjust theproxy_read_timeout
andfastcgi_read_timeout
values to allow for longer request processing times. Restart Nginx after making the changes.
Verify the server's resources: Keep an eye on the server's resource utilization during periods of high traffic. Check to see if your CPU, memory, and disk I/O are not running out of space. If required, think about updating your server or streamlining the code and database queries in your application to boost performance.
Enable the PHP-FPM slow log to find any sluggish requests that can be the reason for the timeouts. Uncomment the'slowlog' directive and set its value to the directory where you wish to store the log file in your PHP-FPM configuration file. Once the changes have been made, restart PHP-FPM. Look for any bottlenecks in your application code by analyzing the log file.
Implement health checks: To run routine health checks on your Nginx and PHP-FPM servers, you can set up a monitoring system or use third-party tools. These checks can assist in finding any problems before they impair service. The server's response time, CPU use, memory utilization, and other pertinent data can all be observed.
Enable error logging: Ensure that PHP-FPM and Nginx error logging are both turned on. Look through the error logs for any pertinent error messages that can offer more information about the reason for the timeouts.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.