rrotstain Posted October 3, 2011 Share Posted October 3, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/ Share on other sites More sharing options...
Muddy_Funster Posted October 3, 2011 Share Posted October 3, 2011 is your php ini file set to allow the fopen url wrapper? have you tried pointing the script to another page, like google.com? Quote Link to comment https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/#findComment-1275168 Share on other sites More sharing options...
AbraCadaver Posted October 3, 2011 Share Posted October 3, 2011 When I navigate to this php from a web browser' date=' I get back an empty page (as if there's an error or something).[/quote'] error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/#findComment-1275282 Share on other sites More sharing options...
rrotstain Posted October 3, 2011 Author Share Posted October 3, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/#findComment-1275338 Share on other sites More sharing options...
rrotstain Posted October 3, 2011 Author Share Posted October 3, 2011 I should also mention that using the URL http://localhost seems to work. But as soon as I introduce a port number to the URL, it doesn't. Not sure why adding a port number (i.e. http://localhost:8090) would make it stop working. --Ronen Quote Link to comment https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/#findComment-1275341 Share on other sites More sharing options...
rrotstain Posted October 3, 2011 Author Share Posted October 3, 2011 Nevermind... fixed it. Didn't realize SELinux was turned on. Turned it into permissive mode and everything started working. Thanks guys. --Ronen Quote Link to comment https://forums.phpfreaks.com/topic/248308-file_get_contents-not-working/#findComment-1275348 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.