Page 1 of 1

file_get_contents via HTTP on same website gets timeout

PostPosted: October 31st, 2016, 10:16 am
by uwe
Precondition:

Two files:

- File "index.php"
- File "test.php"

"index.php" contains:

Code: Select all
<?php

echo "Hello World!";

$c = file_get_contents("http://localhost:43517/test.php");
echo $c;

?>


"test.php" contains:

Code: Select all
<?php

echo "Test";

?>


With "localhost:43517" being the URL of the current project in Visual Studio.

Steps/error:

When calling "http://localhost:43517/index.php" in the browser, the page loads for approx. 60 seconds and then only "Hello World" is printed.

Expected results:

I would expect to immediately get a page in my browser printing "Hello World", followed by "Test".

More information:

- When calling e.g. "http://stackoverflow.com" instead of my localhost URL, everything works as expected.

- When using the above two files on a live Apache webserver, the expected result is correctly displayed.

Question:

Can you comment on whether this is kind of limitation of your used web server?

(e.g. like single-threading or something like this?)

Is there a fix or workaround?

Re: file_get_contents via HTTP on same website gets timeout

PostPosted: October 31st, 2016, 10:31 am
by uwe
This seems to be related due to the fact that the built-in PHP web server is single threaded.

See this similar posting.

Re: file_get_contents via HTTP on same website gets timeout

PostPosted: November 4th, 2016, 3:15 pm
by Miloslav Beno
Hello,

Thanks for the post with scenario.

Yes, that's exactly the issue. PHP Build-in server can handle only one request at a time. You can easily overcome this by moving to other web server, e.g. IIS Express ( which we do have build-in support for), or XAMPP or other Apache distribution.

Thanks!