1

I'm trying to get the content of an external file (youtube json feed) I first tried using file_get_contents() and curl. None of them are giving me any response.

In php.ini allow_url_fopen is set to On. And I also tried turning off safe mode.

error_reporting('E_ALL'); ini_set('display_errors',1); echo file_get_contents('http://gdata.youtube.com/feeds/api/playlists/760E7F6C9B5CD71E?v=2&alt=json'); 

What can be going wrong?

7
  • its error_reporting(E_ALL), also did you check your server log, perhaps you have some kind of restriction. Just lookup your config to see everything installed with <?php phpinfo();?> Commented Jun 11, 2012 at 18:50
  • Changed it to error_reporting(E_ALL); Getting: failed to open stream: Network is unreachable in file.php Commented Jun 11, 2012 at 18:55
  • Some hosts have an outgoing connection firewall type thing, perhaps its set to deny all. Commented Jun 11, 2012 at 18:59
  • Is there any way to figure out if the server has such a firewall? I use a shared hosting with plesk installation. Commented Jun 11, 2012 at 19:05
  • Well your getting an error that suggests as much, look around your control panel for Server > IP Addresses > Firewall or similar, if your stuck open a ticket to your host and get them to fix it. Commented Jun 11, 2012 at 19:13

1 Answer 1

1

Use curl instead of file_get_contents. Something like this:

$url = 'http://gdata.youtube.com/feeds/api/playlists/760E7F6C9B5CD71E?v=2&alt=json'; $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); echo $data; 
Sign up to request clarification or add additional context in comments.

3 Comments

I got no errors and no response. Script online: test.odb-competition.be/test.php
If you get "Network is unreachable" error then it's a network problem and you may contact with your hosting company.
@cloetensbrecht you can enable error reporting in your php.ini file in order to see your php errors.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.