I am slightly baffled.
I am using the bit.ly PHP API to shorten some urls. This works fine on local host - but when I tried it on my server (php running in Apache), file_get_contents() returns an empty string.
I checked my apache logs and cannot see any warning/errors by Apache, so I tried the same command at the CL (using PHP CLI):
>php -a
php > $long_url = some_url_encoded_string;
php > echo file_get_contents($long_url);
{"errorCode": 0, "errorMessage": "", "results": {"http://www.example.html": {"userHash": "abc", "shortKeywordUrl": "", "hash": "xyz", "shortCNAMEUrl": "http://bit.ly/foobar", "shortUrl": "http://bit.ly/foobar"}}, "statusCode": "OK"}
Does anyone know what could be causing this behaviour?
It probably has something to do with PHP configuration. Many servers have different php.inis for CLI and Apache. Check /etc/php5/ to see if there is more than one configuration. Specifically, you should be looking for allow_url_fopen.
EDIT: Actually, Ubuntu ships with that by default, the .ini is located at /etc/php5/apache2/php.ini