When I run the following code on one of my websites:
<?php
$thing = file_get_contents("http://mywebsite.com:8080/Public");
echo($thing);
?>
It returns expected result, the contents of http://mywebsite.com:8080/Public
But when I run it on my other website (hosted on by a different company), it does not display anything. No errors and not the contents of http://mywebsite:8080/Public. However, if I run the following code:
<?php
$thing = file_get_contents("http://somerandomwebsite.com");
echo($thing);
?>
It returns the contents of somerandomwebsite.com. Is there a reason why it works on one of the websites and not the other? Why can it only fetch the contents of the file if the port is 80?
file_get_contentsfails because it cannot retrieve the content at hand. Most likely, a simplistic firewall is blocking all traffic to non-80 ports. You’ll have to use port 80 to avoid these simplistic firewalls.The failure to download the resource makes php emit a warning. Most likely, warnings are not displayed on the production server. Check the server’s log and the
display_errorsanderror_reportingconfigurations.