【发布时间】:2019-07-28 00:42:04
【问题描述】:
我有一个简单的 PHP 脚本,可以从 craigslist 加载 RSS 提要。它已经工作了几个月,然后突然停止了几天前的数据提取。我尝试在我的本地主机上运行脚本,它可以正常工作。我联系了托管该网站的 GoDaddy,但运气不佳。我尝试了另一个托管服务 HostGator 和同样的问题,它不会检索数据。
什么会导致它在共享主机帐户上突然停止工作,但仍然在我的 LocalHost 上工作?
这是简单的 PHP 脚本 -
$rss = new DOMDocument();
$rss->load("Craigslist RSS Feed URL");
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('date')->item(0)->nodeValue,
);
array_push($feed, $item);
}
var_dump($feed);
【问题讨论】:
-
您可以尝试添加
var_dump(file_get_contents('feed url')和var_dump($rss)吗? -
var_dump(file_get_contents('url')) 返回 bool(false)
-
var_dump($rss) 返回 - object(DOMDocument)#1 (35) { ["doctype"]=> NULL ["implementation"]=> string(22) "(省略对象值) " ["documentElement"]=> NULL ["actualEncoding"]=> NULL ["encoding"]=> NULL ["xmlEncoding"]=> NULL ["standalone"]=> bool(true) ["xmlStandalone"]= > bool(true) ["version"]=> string(3) "1.0" ["xmlVersion"]=> string(3) "1.0" ["strictErrorChecking"]=> bool(true) ["documentURI"]= > NULL ["config"]=> NULL ["formatOutput"]=> bool(false) ["validateOnParse"]=> bool(false) ["resolveExternals"]=> bool(false) ["preserveWhiteSpace"]=> bool(true) ["recover"]=> bool(false) etc..
-
好的,这意味着您的服务器无法再访问该 URL。尝试添加此代码,它将输出更多信息用于调试:gist.github.com/atymic/4ca2d1ce823e2d5ec5d827f2b82ed0c5
-
是的,这个 github 示例让我自动屏蔽了大声笑。每当我尝试 Curl 时,它都会自动屏蔽我的 IP
标签: php rss shared-hosting