Reputation: 1254
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)
Upvotes: 0
Views: 793
Reputation: 1254
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
Upvotes: 1
Reputation: 134
I would start from those points:
1. DNS issue?
Maybe issue with DNS table on your server2 (which can not resolve domain2).
from script try to execute function
string gethostbyname ( string $hostname )
OR to check quickly, you also can try to use IP instead of domainname. If it would work the problem was with DNS table. Try to flush DNS caches.
2. Filtration on server? If you are using common hosting, try to write in support too. maybe they can assist. Maybe they are using filtration.
If domain2 is yours OR you have access to its logs. Check access log. If you really get requests from your server2 to domain2.
3. Are you in blacklist of server2? Also possible that your server2 IP in black list of domain2 service.
Upvotes: 0