file_get_contents via HTTP on same website gets timeout

PHP Tools [?] extends Visual Studio with set of advanced features to work more efficiently with PHP code.

file_get_contents via HTTP on same website gets timeout

Postby uwe » October 31st, 2016, 10:16 am

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?
uwe
 
Posts: 21
Joined: October 10th, 2016, 8:39 am

Re: file_get_contents via HTTP on same website gets timeout

Postby uwe » October 31st, 2016, 10:31 am

This seems to be related due to the fact that the built-in PHP web server is single threaded.

See this similar posting.
uwe
 
Posts: 21
Joined: October 10th, 2016, 8:39 am

Re: file_get_contents via HTTP on same website gets timeout

Postby Miloslav Beno » November 4th, 2016, 3:15 pm

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!
Miloslav Beno │ DEVSENSE s.r.o. │ @miloslavbenomiloslav@devsense.com
User avatar
Miloslav Beno
 
Posts: 1252
Joined: January 7th, 2012, 8:36 pm


Return to PHP Tools

Who is online

Users browsing this forum: No registered users and 4 guests

cron

User Control Panel

Login

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests (based on users active over the past 5 minutes)
Most users ever online was 89 on October 15th, 2018, 4:06 pm

Users browsing this forum: No registered users and 4 guests