Problem
file_get_contents()
is returning an empty string for some reason.
Code
index.php
<?php
$value = file_get_contents("http://foo.com/somefile.txt");
echo $value;
?>
php.ini
allow_url_fopen = On
allow_url_include = On
http://foo.com/somefile.txt
69.00000000
My Research
Generally when file_get_contents("http://foo.com/somefile.txt")
returns an empty string, it is due to one of two reasons
somefile.txt
is an empty filephp.ini
hasallow_url_include = Off
$value
should now be 69.00000000
, but the function returns nothing.
Question
Why is $value
empty after the function call?
2
Answers
There are two different kinds of ’empty’. Either the file is actually 0 bytes long (empty string), or the call failed, and the return is FALSE. To quote the docs:
Now, I don’t know why your call failed, but it’s likely to be logged in a webserver error log already, or you can convert these to exceptions to log them yourself.
A third alternative, advisable on a development system, is to set
display_errors
in php.ini to make the problem visible:This includes errors in the output, so that you can see them in the browser.