Nginx-php often prompts 504 Gateway time-out

Source: Internet
Author: User

Problem

Win7 installed on the nginx1.6.2 official website version + Wamp PHP Library, and then the program has PHP use Curl to collect a remote program, but always appear 504 Gateway Time-out prompt! Using PHP inside Wamp, no php-fpm, how to modify max_children parameters?

Startup code

@echo offREM Windows 下无效REM set PHP_FCGI_CHILDREN=5REM 每个进程处理的最大请求数,或设置为 Windows 环境变量set PHP_FCGI_MAX_REQUESTS=1000echo Starting PHP FastCGI...RunHiddenConsole D:/wamp/bin/php/php5.5.12/php-cgi.exe -b 127.0.0.1:9000 -c D:/wamp/bin/apache/apache2.4.9/bin/php.iniecho Starting nginx...RunHiddenConsole D:/nginx/nginx.exe -p D:/nginx

Reply content:

Problem

Win7 installed on the nginx1.6.2 official website version + Wamp PHP Library, and then the program has PHP use Curl to collect a remote program, but always appear 504 Gateway Time-out prompt! Using PHP inside Wamp, no php-fpm, how to modify max_children parameters?

Startup code

@echo offREM Windows 下无效REM set PHP_FCGI_CHILDREN=5REM 每个进程处理的最大请求数,或设置为 Windows 环境变量set PHP_FCGI_MAX_REQUESTS=1000echo Starting PHP FastCGI...RunHiddenConsole D:/wamp/bin/php/php5.5.12/php-cgi.exe -b 127.0.0.1:9000 -c D:/wamp/bin/apache/apache2.4.9/bin/php.iniecho Starting nginx...RunHiddenConsole D:/nginx/nginx.exe -p D:/nginx

Set_time_limit (0);
504 is a Web service report, which is typically a program execution timeout.

How did you solve it, I also have this problem on my side.

504 is usually caused by an application processing time-out, which is not very much related to Nginx.
There are usually several situations that can cause this problem:
1. The program is dealing with a lot of data, or there are dead loops and other problems
2. Create a connection such as a database because there are some reasons why the connection does not occur, and then there is a mechanism for the time-out failure
3. There are some HTTP requests in the program, these requests take too long to execute, resulting in a time-out

If you can't navigate directly to the problem, debug is easy, insert exit anywhere in the code, and if the timeout indicates a timeout after that, move back to exit, or if you don't time out, move ahead until you find the problem.

In the curl request is the time to set the time-out, of course, this is only a suggestion, means if the collection of excessive content is recommended not to be done in PHP, put in a list as short as possible to complete the front-end refresh method to step into the process, so it will be better, I have done so before

To modify the Nginx configuration:
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64k;
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 256k;

Set up PHP scripts

Set_time_limit (0);
Ignore_user_abort ();

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.