Reputation: 4314
I am trying to access RSS live cricket score feed of espncricinfo.
My php code is like this
$xml = simplexml_load_file("http://static.cricinfo.com/rss/livescores.xml");
but it is throwing an error like this.
Warning: simplexml_load_file(http://static.cricinfo.com/rss/livescores.xml) [function.simplexml-load-file]: failed to open stream: Permission denied in /home/www/java8.in/txtWeb/demo.php on line 11
looking for a solution.
Upvotes: 3
Views: 10546
Reputation: 1358
If you are running with SELinux you may need to allow Apache access to the network
setsebool -P httpd_can_network_connect on
Upvotes: 0
Reputation: 4314
I found that some shared hosting provider do not support the access of external url although allow_url_fopen
is set to 1.
Possible solution for problems :
Two solutions are mentioned by Shankar Damodaran in Above answer
Another solution or alternate way I found is, ini_set
function.
You can put following code in your php file to modify php.ini
file properties.
ini_set('allow_url_fopen', 'on');
Upvotes: 0
Reputation: 68476
Your code actually works ,but you need to have allow_url_fopen
to be set 1
or ON
to achieve what you are doing.
Check the PHP Manual here
on how to do that.
<?php
$xml = simplexml_load_file("http://static.cricinfo.com/rss/livescores.xml");
print_r($xml);
OUTPUT:
SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [title] => Cricinfo Live Scores [ttl] => 2 [link] => http://www.cricinfo.com [description] => Latest scores from Cricinfo [copyright] => (c)Cricinfo [language] => en-gb [pubDate] => Tue, 04 Feb 2014 19:12:01 +0000 [item] => Array ( [0] => SimpleXMLElement Object ( [title] => Bangladesh v Sri Lanka 314/5 * [link] => http://www.cricinfo.com/ci/engine/match/690349.html?CMP=OTC-RSS [description] => Bangladesh v Sri Lanka 314/5 * [guid] => http://www.cricinfo.com/ci/engine/match/690349.html ) [1] => SimpleXMLElement Object ( [title] => South Africa 300/10 v South African Composite XI 24/3 * [link] => http://www.cricinfo.com/ci/engine/match/714095.html?CMP=OTC-RSS [description] => South Africa 300/10 v South African Composite XI 24/3 * [guid] => http://www.cricinfo.com/ci/engine/match/714095.html ) [2] => SimpleXMLElement Object ( [title] => Guyana 36/1 * v Windward Islands [link] => http://www.cricinfo.com/ci/engine/match/708797.html?CMP=OTC-RSS [description] => Guyana 36/1 * v Windward Islands [guid] => http://www.cricinfo.com/ci/engine/match/708797.html ) [3] => SimpleXMLElement Object ( [title] => Sri Lanka Cricket Women's XI v England Academy Women [link] => http://www.cricinfo.com/ci/engine/match/710579.html?CMP=OTC-RSS [description] => Sri Lanka Cricket Women's XI v England Academy Women [guid] => http://www.cricinfo.com/ci/engine/match/710579.html ) [4] => SimpleXMLElement Object ( [title] => Sydney Sixers v Perth Scorchers [link] => http://www.cricinfo.com/ci/engine/match/654097.html?CMP=OTC-RSS [description] => Sydney Sixers v Perth Scorchers [guid] => http://www.cricinfo.com/ci/engine/match/654097.html ) ) ) )
<?php
$url = "http://static.cricinfo.com/rss/livescores.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xmlresponse = curl_exec($ch);
$xml=simplexml_load_string($xmlresponse);
print_r($xml);
Upvotes: 3