2017-05-04 107 views
0
我在使用PHP的問題,即超時像

Windows下的PHP的file_get_contents在localhost

file_get_contents("http://127.0.0.1/test.php") 

做任何事情的時候,我還使用curl和東西嘗試

返回504,它工作正常,當我試圖從其他地方收到的數據,但是當它的本地主機,我收到了504

我在Windows上是10 64 PHP版本是7.0.18 nginx的版本是1.8.0

到目前爲止,我已經嘗試了所有可怕的設置權限ctories,我已經嘗試了不同的用戶代理等,我甚至試圖複製了同樣的要求作爲我的Chrome瀏覽器的做法,但我的運氣。

我得到這個nginx的錯誤error.log中。

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");

test.php的

"Hello, this is a test"

讓我知道如果你需要更多的信息。

回答

0

設置maximum_execution_time(默認爲30秒)到一個更大的值 - 例如距離您的php.ini文件60秒。或者更好地優化您的indexsss.php腳本 - 因爲它會導致此錯誤。

UPDATE:

<?php 
$options = ['http'=>[ 
    'method'=>"GET", 
    'header'=>"Accept-language: dk\r\n" 
    ] 
]; 

$ctx = stream_context_create($options); 

$test = file_get_contents('http://127.0.0.1/test.php', false, $ctx); 
?> 

http://php.net/manual/en/info.configuration.php#ini.max-execution-time

http://php.net/manual/en/function.stream-context-create.php

+0

嗨,indexxx是不是這個問題。文件僅僅是包含了很多的註釋掉了代碼,而不是評論的唯一線路 '$測試=的file_get_contents(「http://127.0.0.1/test.php」);' 和所有的test.php確實是輸出一個字符串,所以並不複雜。不應該超過30秒。 –

+0

然後test.php裏面有什麼? – marmeladze

+0

我剛剛發佈了上面的一行。 '「你好,這是一個考驗」' –

0

你配置任何調試(Xdebug的遠東)。如果是,您需要將其配置爲支持併發線程。

+0

根本就沒有這樣的東西,我有一個ioncube加載程序,但在我想象的這個例子中沒有使用它。 –