PHP and PEAR package RSS

Associate
Joined
6 Dec 2002
Posts
661
Location
Belfast
I can't seem to get the XML\RSS.php PEAR package to work. I've downloaded it fine but I can't seem to get the require_once directive to import the package. I also downloaded the DB.php PEAR package and this works perfectly. Any ideas?
 
Is your Pear directory part of your include path?
What is the code you're using for the require_once line?
What error message are you getting?

You would normally include the RSS package via:
Code:
require_once 'XML/RSS.php';
 
I'm not actually getting an error message. I'm bit of a PHP newbie so is there somewhere I should turn on error messaging?

Basically what I have are two files, db_test.php and rss_test.php:

db_test.php
Code:
<?php
require_once 'DB.php';
echo 'hello!';
?>
rss_test.php
Code:
<?php
require_once 'XML/RSS.php';
echo 'hello!';
?>
When I launch the db_test.php I see the "hello!" output but not when I run the rss_test.php. I also tried running the following script using the RSS.php package:
Code:
<?php
require_once 'XML/RSS.php';

echo 'hello!';

$rss =& new XML_RSS("http://slashdot.org/slashdot.rdf");
$rss->parse();

echo "<h1>Headlines from <a href=\"http://slashdot.org\">Slashdot</a></h1>\n";
echo "<ul>\n";

foreach ($rss->getItems() as $item) {
    echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></li>\n";
}

echo "</ul>\n";
?>
When this script didn't work I knew something wasn't right.

Any help is much appreciated.
 
When you say you 'downloaded' the packages, did you just download them straight off the Pear site? In case you have, you're likely to run into a great deal of problems with package dependencies (RSS requires XML_Parser and Pear, for example).

Pear packages should be ideally installed using the command line package manager with pear install <packagename>. Installing RSS would require pear install --alldeps XML_RSS.

As for error messaging, at the top of your script, add:
Code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
 
As far as I can remember I tried downloading the RSS package using the install command but it complained about dependencies, so I tried the --alldepends switch but I got a message saying that it was unable to download dependencies. Therefore I used the install command to download the dependencies first and then the RSS package. This seemed to work fine but I guess this might be where the problem lies.

Is it possible to just try downloading the package again using the --alldepends switch over the top of the existing install? If so I'll try this tonight when I get home from work.
 
blue_harvester said:
Is it possible to just try downloading the package again using the --alldepends switch over the top of the existing install? If so I'll try this tonight when I get home from work.
Yes, it won't download what you already have. The option is --alldeps, not --alldepends.

If you've got everything through Pear, then the installation process shouldn't have caused the problems, but you may well be missing a dependency higher up. As far as I can see, XML_RSS needs XML_Parser, XML_Tree and Pear, but I'm not certain about that.

When I launch the db_test.php I see the "hello!" output but not when I run the rss_test.php
If this is happening then it is likely that a Fatal Error is occuring in your require_once line, but you need to enable display_errors or up the level of reporting to see exactly what the problem is. It's difficult to suggest a fix without knowing the exact error :).
 
Got it working guys. The XML_Parser was missing. I had to download his package separately as --alldeps didn't seem to work. Anyway it's working now so thanks everyone for the input.
 
Back
Top Bottom