php curl nginx 499 error

When developing an LNMP project in Windows, you will encounter multiple sets of PHP code on the same machine. If you use PHP to access other projects through curl, a timeout will be prompted.

 

After trying, you can solve it in the following way!

 

When you first view the nginx log, you see:

192.168.1.189 - - [17/Oct/2016:14:34:17 +0800] "GET /proxy/data/10002?asjdflasjkld=a12&sign=4033d03c16083e054f118a46247554653473fde0 HTTP/1.1" 499 0 "-" "-"

 

After searching, nginx canceled the request because the request timed out, that is, a "deadlock" problem occurred when accessing php (my own words). To solve this problem, please refer to the following configuration:

 

Assuming the local hosts file looks like:

127.0.0.1 a.com

127.0.0.1 b.com

Access b.com from a.com

 

The nginx configuration is as follows, pay attention to the red part:

server{

listen 80;

server_name a.com;

location / {

   rewrite ^(.*)$ /index.php?$1 break;

        index index.php;

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

}

}

server{

listen 8001;

server_name b.com;

location / {

    rewrite ^(.*)$ /index.php?$1 break;

        index index.php;

        fastcgi_pass 127.0.0.1:9001;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

}

}

 

In this way, the two projects (ports 80 and 8001) are connected to ports 9000 and 9001 of php-cgi respectively. Note: nginx can be set to 80, but php must be separated.

 

The reason is that there is no multi-threading in phpcgi under windows! The number of threads can be configured when cgi starts in linux, so there is no problem. (I don’t study the internal cause anymore, ask Baidu)

 

Solution ideas:

1. A.com is connected to port 9000 after startup, and b.com is connected to port 9001 after startup. The two will not cause the timeout problem caused by the occupation of cgi resources.

2. CURLOPT_HTTPHEADER needs to be configured when calling curl in php 

$url = 'http://127.0.0.1:8001'; // domain name of b
$ch = curl_init($url);
curl_setopt_array(
    $ch, array(
         CURLOPT_HTTPHEADER=>array(
                "Host: b.com"
         ),
         // Other parameters
    )
);
$ret = curl_exec($ch);
// process result

 

In this way, after the local hosts mapping can be solved, curl can successfully find the problem of related websites!

 

Please refer to the attachment for the cmd.zip file for starting and stopping phpcgi.

You can take a look at RunHiddenConsole, which is used to hide the nginx command window when using a non-integrated environment (such as phpStudy).

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326488817&siteId=291194637