Jump to content

file_get_contents not working


rrotstain

Recommended Posts

Hi guys,

 

I have a very simple php script that's supposed to work but doesn't. The script looks like this...

 

<?php

$response = file_get_contents("http://localhost:8090/MyWebApp/MyServlet", false, NULL)

echo $response

?>

 

which seems to return nothing. This is supposed to call a java servlet on the local machine. However, the servlet does not get called (I put a breakpoint in the servlet so I'd know if it were called).

 

When I navigate to this php from a web browser, I get back an empty page (as if there's an error or something). However, if I change the above line to use http://www.google.com as the URL, it works (I can hit the php page from my browser and get back a google-looking page, minus some pictures and what not).

 

For some reason, the call to a localhost URL does not seem to work, even though the servlet is, in fact, running. I have tested this by calling "curl http://localhost:8090/MyWebApp/MyServlet" from my linux terminal and correctly getting the servlet response.

 

Does anyone know why this does not work in PHP?

 

Thanks,

--Ronen

Link to comment
https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/
Share on other sites

Thanks for the suggestions.

 

Allow_url_fopen is set to "On" in php.ini file so I think that part should be good.

 

After adding the lines:

error_reporting(E_ALL);
ini_set('display_errors', '1');

 

I now get the error

failed to open stream: Permission denied in /home/roner/public_html/fgc.php

 

Not sure what kind of permissions it's talking about.  All directories leading up to this one have execute permission granted and the fgc.php file is chmod'ed as 777.

 

Any ideas?

 

Ronen

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.