Problem Summary: Php-curl access timeout in Nginx, normal in CLI environment

Source: Internet
Author: User

In order to test the local PHP code, due to computer memory limitations, unable to run the virtual machine, so set up a local Web services debugging environment Windows, Nginx, php-cgi, MySQL

Because the Xdebug Debug Service 9000 port is occupied, PHP-CGI uses 9001 ports and needs to respond to changes in Nginx configuration

1 fastcgi_pass 127.0.0.1:9001;

Start the service:

start /b nginx. Exenginx Net Start Mysql56nginx CD path_to_phpphp> Php-cig.exe-b 127.0.0.1:9001

Stop Service

Php> Ctrl +c^phpcd  path_to_nginxnginxnet  stop Msyql56nginx> Nginx.exe-s stop

have been running very smooth, and today suddenly encountered a problem, found in PHP with a curl request, the Nginx access request will time out, in the CLI environment normal.

So on Baidu search, bitter search without fruit, finally found on google results, the address is as follows:
Http://stackoverflow.com/questions/13813667/php-curl-timing-out-but-cli-curl-works?rq=1

Because the local only started a php-cgi process, when the user accesses a PHP page, Nginx has occupied the process, in the process of initiating an HTTP request, Nginx found that the only process has been occupied and caused blocking, thus causing the deadlock, until the timeout.

The solution is to start multiple php-cgi processes, Answer the Lord gave a Python management script he wrote: spawn-php.py, after the download run found Win32process module, and then to Baidu Search Win32process installation package, in Yang Qing personal blog saw the address, Bo Master also puzzled in Baidu search win32process installation Package, there are always some irrelevant things, so the address is recorded down.

: http://sourceforge.net/projects/pywin32/files/

Download the corresponding local Python version of the installation package, installation completed, run spawn-php.py script encountered a few minor problems, the script is written for Python2, the local loaded is python3.4, so there are two points need to change:

    1. Print is used as a function, parentheses are added
    2. Dict has no iteritems attribute, use the Items property directly to

Run script spawn-php.py 9001 10 to start 10 php-cgi processes 127.0.0.1:[9001-9010].

Modify Nginx Configuration

1 upstream Php_farm {2Server 127.0.0.1:9001 weight=1;3Server 127.0.0.1:9002 weight=1;4Server 127.0.0.1:9003 weight=1;5Server 127.0.0.1:9004 weight=1;6Server 127.0.0.1:9005 weight=1;7Server 127.0.0.1:9006 weight=1;8Server 127.0.0.1:9007 weight=1;9Server 127.0.0.1:9008 weight=1;TenServer 127.0.0.1:9009 weight=1; OneServer 127.0.0.1:9010 weight=1; A } -# ... -Fastcgi_pass Php_farm;

Re-loading Nginx configuration

1 nginx> nginx.exe-s Reload

Normal operation!

Problem Summary: Php-curl access timeout in Nginx, normal in CLI environment

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.