0

I'm having an issue with PhP where it times out when doing anything like

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

I've also tried using CURL and stuff, it works fine when I'm trying to recieve data from somewhere else, but when it's local host I get a 504.

I'm on Windows 10 x64 Php version is 7.0.18 nginx version is 1.8.0

So far I've tried settings permissions for all the directories, I've tried different user-agents etc, I've even tried replicating the same request as my chrome does in the browser, but I'm out of luck.

I get this nginx error in 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"

This is what I get from my 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"

This is the php errors i get from php_errors.log

[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 is working fine when using the browser to access it. So I'm pretty clueless, I hope someone can help me out.

indexsss.php containts lots of commented code(Hence the line number of execution) The only uncommented code is this.

$test = file_get_contents("http://127.0.0.1/test.php");

test.php

"Hello, this is a test"

Let me know if you need more info.

2 Answers2

0

Set maximum_execution_time (defaults to 30 seconds) to a bigger value - e.g. 60 seconds from your php.ini file. Or better optimize your indexsss.php script - as it causes this error.

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

marmeladze
  • 6,468
  • 3
  • 24
  • 45
  • Hi, indexxx is not the issue with this. File is just containing a lot of code that's commented out, the only line not commented is `$test = file_get_contents("http://127.0.0.1/test.php");` And all test.php does is outputting a string, so nothing complicated. Shouldn't take more than 30 seconds. – Rasmus Kjeldsen May 04 '17 at 11:09
  • what's inside test.php then? – marmeladze May 04 '17 at 11:11
  • I posted the line above just now. `"Hello, this is a test"` – Rasmus Kjeldsen May 04 '17 at 11:25
  • i once had such problem. then added a stream context - and it suddenly fixed. i'll update my answer with a stream example. http://php.net/manual/en/function.stream-context-create.php – marmeladze May 04 '17 at 11:34
  • I just tried with `stream_context_create`, and it didn't solve it unfortuneately. Still returns the 504 How ever, I'm not able to replicate the issue on my debian vm, so I might have to go through all the config files again. – Rasmus Kjeldsen May 04 '17 at 11:51
0

Do you have any debug configured (xdebug f.e.). If yes you need to configure it to support simultaneous threads.

Ilya Kovalyov
  • 484
  • 2
  • 10