这是一个wordpress博客rss提要
从domain1,当使用此脚本时,它将适用于domain2,但不适用于domain1。
从domain2,当使用此脚本时,它适用于domain2和domain1
我的假设是,这一定是一个权限错误,但我不知道什么设置不正确(domain2可以为两个域获取博客,domain1将为domain2获取博客,但不能为domain1获取博客)
当尝试使用cURL时,结果相同,domain1可以获取domain2,但不能获取domain1,而domain2可以从domain1和domain2 获取提要
文件集内容
$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样式和结果
/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)
好的,问题与服务器有关。。。
来自服务器管理员Added www.domain1.com to the /etc/hosts file so that it looked to itself for the site.
感谢大家的帮助,希望这能帮助到未来有类似问题的其他人
我将从以下几点开始:
1.DNS问题可能是服务器2上的DNS表出现问题(无法解析domain2)。从脚本尝试执行函数string gethostbyname ( string $hostname )
或者为了快速检查,您也可以尝试使用IP而不是域名。如果它能工作,问题是DNS表。尝试刷新DNS缓存。
2.服务器上的过滤如果你使用的是通用主机,也可以尝试写支持。也许他们可以提供帮助。也许他们在使用过滤。
如果domain2是您的,或者您可以访问它的日志。检查访问日志。如果你真的收到了从服务器2到域2的请求。
3.你在server2的黑名单中吗也有可能你的服务器2 IP在域2服务的黑名单中。