猿问

nginx下的php做的socket访问一直超时,环境是win10

在win10 安装了php+nginx+mysql,phpinfo打印是正常的,但是在写了一个简单的socket的demo后,nginx一直报超时。

$fp = fsockopen('localhost',80,$errno,$errstr,10); // 10秒超时if (!$fp) {    echo 'Error Code:'.$errno. '--Error Info:'.$errstr;    die;
}
$http= '';
$http .= "GET /socket/server.php HTTP/1.1\r\n";

$http .= "Host: localhost\r\n";
$http .= "Connection: close\r\n\r\n";

fwrite($fp, $http);
$res = '';while(!feof($fp)) {
    $res .= fgets($fp);
}echo $res;

niginx报错:
2019/03/07 00:46:18 [error] 18316#16624: *1 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /socket/client.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"

求各路大侠指点迷津


动漫人物
浏览 637回答 1
1回答

慕田峪9158850

报文不对吧。首行之后,应该是接两组 \r\n ?你先用 telnet 完成一个正确的报文请求,并得到一个正确的响应之后,再写代码吧。
随时随地看视频慕课网APP
我要回答