【发布时间】:2015-07-29 13:52:21
【问题描述】:
我希望有人能给我一些建议。
我在使用 SimpePie 更新我的 MySQL 数据库时遇到问题。我正在使用它来获取基于以下代码的小调整的 RSS 提要数组。
奇怪的是脚本在我自己在浏览器中执行时运行良好,但当它由 GoDaddy 的 CRON 任务执行时却不行。
我的 CRON 任务看起来像这样,没什么神奇的:
/web/cgi-bin/php5 "$HOME/html/gia_rss_cron.php"
通过GoDaddy返回的错误信息如下:
致命错误: 在第 167 行的 /home/content/40/xxx/html/php2/library/SimplePie/Item.php 中的非对象上调用成员函数 get_base()
完成这项工作的代码基于此代码,我尝试了 SimplePie 1.3.1 以及 1.4dev 以防万一。两者都抛出相同的错误,但仅在通过 CRON 运行时提及,而不是在我手动运行文件时。
<?php
require_once('php/autoloader.php');
$feed = new SimplePie();
// Create a new instance of SimplePie
// Load the feeds
$urls = array(
'http://abcfamily.go.com/service/feed?id=774372' => 'abc',
'http://www.insideaolvideo.com/rss.xml' => 'aolvideo',
'http://feeds.bbci.co.uk/news/world/rss.xml' => 'bbcwn',
'http://www.bing.com' => 'bing',
'http://sports.espn.go.com/espn/rss/news' => 'espn',
'http://www.xfinitytv.com/' => 'xfinitytv',
);
$feed->set_feed_url(array_keys($urls));
$feed->enable_cache(false);
//$feed->set_cache_location('cache');
//$feed->set_cache_duration(1800); // Set the cache time
//$feed->set_item_limit(1);
$success = $feed->init(); // Initialize SimplePie
$feed->handle_content_type(); // Take care of the character encoding
?>
<?php require_once("inc/connection.php"); ?>
<?php require_once("inc/functions.php"); ?>
<?php include("inc/header.php"); ?>
<?php
// Sort it
$feed_items = array();
// $feed_items is an array
$items = $feed->get_items();
//$items is everything that $items = $feed->get_items(); produces
$urls = array_unique($urls);
// $url = is an empty $
foreach ($urls as $url => $image) {
$unset = array();
$feed_items[$url] = array();
foreach ($items as $i => $item) {
if ($item->get_feed()->feed_url == $url) {
$feed_items[$url][] = $item;
$unset[] = $i;
}
}
foreach ($unset as $i) {
unset($items[$i]);
}
}
foreach ($feed_items as $feed_url => $items) {
if (empty($items)) { ?>
<div class="item element" data-symbol="<?php echo $urls[$feed_url] ?>" name="<?php echo $urls[$feed_url] ?>">
<div class="minimise"><img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/>
<div class="minimise2">
<a href="<?php echo $feed_url; ?>"><h2>Visit <?php echo $urls[$feed_url] ?> now!</h2></a>
</div></div>
<div class="maximise">
<a href="<?php echo $feed_url; ?>"><h2>Visit <?php echo $urls[$feed_url] ?> now!</h2></a>
</div></div>
<?
continue;
}
$first_item = $items[0];
$feed = $first_item->get_feed();
?>
<?php
$feedCount = 0;
foreach ($items as $item) {
$feedCount++;
?>
<div class="item element" " data-symbol="<?php echo $urls[$feed_url] ?>" name="<?php echo $urls[$feed_url] ?>">
<div class="minimise"><strong id="amount"><?php echo ''.$feedCount; ?></strong>
<img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/>
<div class="minimise2"><a href="<?php echo $item->get_permalink(); ?>">
<h2><?php echo $item->get_title(); ?></h2></a>
</div></div>
<div class="maximise"><a href="<?php echo $item->get_permalink(); ?>">
<h2><?php echo $item->get_title(); ?></h2></a><br><p><?php echo $item->get_description(); ?></p>
</div></div>
<?php
}
}
?>
<?php require("inc/footer2.php"); ?>
更新:从 SimplePie 库的 item.php 部分添加代码以防万一,这是我能看到的唯一第 167 行调用该函数的代码。虽然脚本再次在我的浏览器中工作,但不能通过 CRON(不知道这会给我们带来什么,以缩小问题范围)。
还尝试在 PHP 上报告错误,没有其他错误或脚本从浏览器引发的警告。
/**
* Get the base URL value from the parent feed
* Uses `<xml:base>`
* @param array $element
* @return string
*/
public function get_base($element = array())
{
return $this->feed->get_base($element);
}
【问题讨论】:
-
你发布的代码没有调用
get_base() -
get_base() 错误来自我未修改的 SimplePie 核心包。
-
@Organizer 如果你在核心中注释掉 get_base() 来测试,会发生什么?
-
对simplepie一无所知,但在您的包含中,您使用的是相对路径。尝试更改这些包含并在路径定义中使用
dirname(__FILE__)。 -
不幸的是,用 dirname(FILE) 更新并没有做出任何改变