This is a wordpress blog rss feed
From domain1, when using this script it will work for domain2 but not domain1.
From domain2, when using this script it works for both domain2 and domain1
my assumption is that it must be a permissions error, but I don't know what is not set properly (domain2 can fetch the blog fine for both domains, and domain1 will fetch the blog for domain2, but not domain1)
Same results when trying to use cURL, domain1 can fetch domain2, but not domain1 while domain2 can fetch feed from both domain1 and domain2
file_get_contents
$feedUrl = 'http://domain1.com/blog/feed/';
$feedUrl = 'http://domain2.com/blog/feed/';
$rawFeed = file_get_contents($feedUrl);
$xml = new SimpleXmlElement($rawFeed);
$i = 0;
foreach($xml->channel->item as $post)
{
$post->link = str_replace('&', '&', $post->link);
$date = new DateTime($post->pubDate);
if($i == 5) break; // number of feed items
$title = '<a href="' . $post->link . '" title="' . $post->title . '" class="feed-link">' . $post->title . '</a>';
?>
<p><?php echo $title; ?></p>
<?php
$i++;
}
?>
cURL
<?php
$feedUrl = 'http://domain1.com/blog/feed/';
$feedUrl = 'http://domain2.com/blog/feed/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feedUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: text/xml'
));
$rawFeed = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
$xml = new SimpleXMLElement($rawFeed);
echo "<pre>";
var_dump($obj);
echo "</pre>";
?>
URL styles I have tried and results
/www/domain1/blog/feed/ (file or folder does not exist, which is accurate)
http://domain1.com/blog/feed/ (timeout)
http://555.555.555.555/blog/feed (ip address) (timeout)
Okay, the problem was server related...
from server admin Added www.domain1.com to the /etc/hosts file so that it looked to itself for the site.
Thank you everyone for your help, hopefully this will help anyone else who has a similar issue in the future