【问题标题】:Operation timed out after 35007 milliseconds with 0 bytes received操作在 35007 毫秒后超时,收到 0 个字节
【发布时间】:2017-08-31 22:16:09
【问题描述】:

我在 windows 7 上安装了 nginx1.10 和 php5.6,但是我发现当我访问该页面时,它无法向使用相同侦听端口的同一脚本发出 curl 请求。

http://localhost/a.php中有一个curl请求,它向http://localhost/phpinfo.php发出一个curl请求,但是Error:Operation timed out after 35007 milliseconds with 0 bytes received出错了。

server {
    listen 80;
    server_name localhost;
    root d:/localhost;
    index index.html index.htm index.php;
    autoindex on;
    autoindex_localtime on;

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}




http://localhost/a.php


<?php
function makeRequest($url, $params, $method = 'GET')
{
    $ch = curl_init();
    if ($method == 'GET') {
        $url .= '?' . http_build_query($params);
    } else {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    }

    if (substr($url, 0, 6) == 'https:') {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'ApiClient/v1.0');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 35);


    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    $error = curl_error($ch);

    curl_close($ch);
    print_r($info);
    var_dump($error);
    return $result;
}


$url = 'http://localhost/phpinfo.php';
makeRequest($url, []);

输出:

Array
(
    [url] => http://localhost/phpinfo.php?
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 96
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 35.007
    [namelookup_time] => 0.016
    [connect_time] => 0.219
    [pretransfer_time] => 0.219
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 127.0.0.1
    [certinfo] => Array
        (
        )

    [primary_port] => 80
    [local_ip] => 127.0.0.1
    [local_port] => 55978
)

D:\localhost\a.php:37:string 'Operation timed out after 35007 milliseconds with 0 bytes received' (length=66)

我发现如果使用不同的端口,发起请求的PHP使用A端口,响应请求的PHP使用另一个端口,不会出现执行超时。

【问题讨论】:

  • 因为php-cgi不是php-fpm,所以php-cgi不会自动启动新进程,所以一旦被占用就会被锁定

标签: php nginx windows-7


【解决方案1】:

我知道为什么了,因为php-cgi不是php-fpm,php-cgi不会自动启动新进程,所以一旦被占用就会被锁定。

【讨论】:

    猜你喜欢
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 2020-09-07
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    相关资源
    最近更新 更多