我在使用 PhP 时遇到问题,在执行类似操作时会超时
file_get_contents("http://127.0.0.1/test.php")
我也尝试过使用 CURL 和其他东西,当我尝试从其他地方接收数据时它工作正常,但是当它是本地主机时我得到 504。
我在 Windows 10 x64 Php 版本是 7.0.18 nginx 版本是 1.8.0
到目前为止,我已经尝试过为所有目录设置权限,尝试过不同的用户代理等,我什至尝试过在浏览器中复制与我的 chrome 相同的请求,但我不走运。
我在 error.log 中得到这个 nginx 错误。
2017/05/04 10:26:33 [error] 7732#5384: *5 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 connecting to upstream, client: 127.0.0.1, server: _, request: "GET /test.php HTTP/1.0", upstream: "fastcgi://[::1]:9123", host: "127.0.0.1"
这是我从我的 access.log 中得到的。
127.0.0.1 - - [04/May/2017:10:25:33 +0200] "GET /indexsss.php HTTP/1.1" 504 584 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
127.0.0.1 - - [04/May/2017:10:25:33 +0200] "GET /favicon.ico HTTP/1.1" 404 570 "http://127.0.0.1/indexsss.php" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
127.0.0.1 - - [04/May/2017:10:26:33 +0200] "GET /test.php HTTP/1.0" 504 182 "-" "PHP"
这是我从 php_errors.log 得到的 php 错误
[04-May-2017 10:26:33 Europe/Copenhagen] PHP Warning: file_get_contents(http://127.0.0.1/test.php): failed to open stream: HTTP request failed! in C:\Servers\nginx-1.8.0\html\local\indexsss.php on line 208
[04-May-2017 10:26:33 Europe/Copenhagen] PHP Fatal error: Maximum execution time of 30 seconds exceeded in C:\Servers\nginx-1.8.0\html\local\indexsss.php on line 208
http://127.0.0.1/test.php在使用浏览器访问时工作正常。所以我很无能为力,希望有人能帮助我。
indexsss.php 包含大量注释代码(因此执行的行号)唯一未注释的代码是这个。
$test = file_get_contents("http://127.0.0.1/test.php");
测试.php
"Hello, this is a test"
如果您需要更多信息,请告诉我。