Using RSS - error

4 views
Skip to first unread message

Michele

unread,
May 30, 2011, 9:29:55 AM5/30/11
to Ariadne
Tring to use ar\connect\rss module.

Create a page with the following code (the example in your doc)
-----
<pinp>
$rss = ar('connect/rss')->client( 'http://www.nytimes.com/services/
xml/rss/nyt/GlobalHome.xml' );
echo '<ul>';
foreach ( $rss->items as $item ) {
echo '<li><a href="'.$item->link.'">'.$item->title.'</a></li>';
}
echo '</ul>';
</pinp>
-----

When I try to access the page I got the following error:
----
Error on line 4 in readrss.html on object /sites/normale/
Invalid argument supplied for foreach()

Warning: Invalid argument supplied for foreach() in /opt/ariadne/lib/
modules/mod_filestore.phtml(170) : runtime-created function on line 4
----

Can you help me please?

Thank you in advance,
Michele

Auke

unread,
May 30, 2011, 12:00:55 PM5/30/11
to Ariadne
On May 30, 3:29 pm, Michele <fiaschett...@gmail.com> wrote:
> Error on line 4 in readrss.html on object /sites/normale/
> Invalid argument supplied for foreach()
>
> Warning: Invalid argument supplied for foreach() in /opt/ariadne/lib/
> modules/mod_filestore.phtml(170) : runtime-created function on line 4
> ----
>
> Can you help me please?

There is probably a problem getting the given URL. I've tried your
code and it works for me, but I believe the nytimes has a quota system
these days, so if you request the rss feed to often, it will stop
sending it. To catch this you will at least have to add some error
checking, e.g.:

<pinp>
$rss = ar('connect/rss')->client()->get( 'http://www.nytimes.com/
services/xml/rss/nyt/GlobalHome.xml' );
if ( !$rss || ar_error::isError( $rss ) ) {
echo 'The RSS feed could not be found';
} else {
// ... normal handling.
}
</pinp>

To make sure you don't hit the quota, you'll have to cache the rss
feed. There's no caching in the AR lib yet, but the good old Ariadne
caching methods work just fine here. So do something like this:

<pinp>
$rss = getdatacache( 'mynytimesfeed' );
if ( !$rss ) {
$rss = ar('connect/rss')->client()->get( 'http://..../' );
if ( $rss && !ar_error::isError( $rss ) ) {
savedatacache( 'mynytimesfeed', $rss, 1 );
} else {
echo 'Sorry, could not get the feed.';
$rss = false;
}
}
if ($rss) {
// normal handling again
}
</pinp>

Important: the datacache is stored in the object this template is
called. So make sure you always call this template on the same object
or you will still hit the quota limit.

Read more about the caching methods at http://www.ariadne-cms.org/docs/reference/classes/pobject/cache/

Regards,
Auke van Slooten
Muze

Michele Fiaschi

unread,
May 30, 2011, 12:23:38 PM5/30/11
to ariad...@googlegroups.com
trying your example (with different feed rss) but I always get:
--Sorry, could not get the feed--

Mike

ps. Could be something wrong in my ariadne libs? I'm actually using 2.7.3, if I would update to 2.7.5 which is the easiest way? The guy was working as system administrator has changed office, now I can access to mysql db and to the web root (through ssh) but I have not administrator skills..

2011/5/30 Auke <a.c.van...@gmail.com>

Auke

unread,
May 31, 2011, 4:22:24 AM5/31/11
to Ariadne
On 30-5-2011 18:23, Michele Fiaschi wrote:
> trying your example (with different feed rss) but I always get:
> --Sorry, could not get the feed--
I don't think so, but it could be. However, there is a simpler way to
check what is going wrong. Try to get the contents of the url in a
seperate script, something like this:

<pinp>
$client = ar('http')->client();
$result = $client->get( 'http://..../' );
echo '<pre>';
echo $client->responseHeaders;
echo '</pre>';
echo $result;
</pinp>

That should give you the complete result and the headers. If you
again
don't get any result, then try another url, one that you know should
work and try that. If that also fails, then your webserver is most
likely behind a firewall and cannot access other servers on the
internet...
Try if wget from the command line works to check that. e.g.:

wget http://www.ariadne-cms.org/

> > ps. Could be something wrong in my ariadne libs? I'm actually using
> > 2.7.3, if I would update to 2.7.5 which is the easiest way? The guy
> > was working as system administrator has changed office, now I can
> > access to mysql db and to the web root (through ssh) but I have not
> > administrator skills..
I haven't checked the changes, but I don't think we did any serious
bugfixes on the http client or rss lib there... I don't know how
Ariadne
is installed on your server. If installed from the zip/tar package
then
it should be a matter of unzipping/untarring the new version over the
old one and checking the grants on the files directory. Make sure you
have a backup first though ( files and database ). If you use svn,
then
svn up to the latest tag (2.7.5, but I think 'latest' will also work.)
You may need to run the upgrade script, which is in the bin
directory.
Make sure you run it as the web user, probably www-data.

If you are not sure about this, first try to restore the backup on
another machine and test the upgrade there. That way you are also
sure
you have a working backup :)

regards,
Auke van Slooten
Muze

Michele

unread,
Jun 3, 2011, 5:54:21 AM6/3/11
to Ariadne
Hi Auke,

> I don't think so, but it could be. However, there is a simpler way to
> check what is going wrong. Try to get the contents of the url in a
> seperate script, something like this:
>
> <pinp>
>    $client = ar('http')->client();
>    $result = $client->get( 'http://..../');
>    echo '<pre>';
>    echo $client->responseHeaders;
>    echo '</pre>';
>    echo $result;
> </pinp>
>
> That should give you the complete result and the headers.

No results here, I get only the string 'array' on my page

> wgethttp://www.ariadne-cms.org/

It works and when I use connect->db to read from other servers it
works fine.

I must look for another way to include rss in my site. I really don't
understand what's wrong.


Thank you for you notes about upgrade, I will try as soon as possible
on a backup server hoping it works fine.

Have a nice weekend,
Michele

Auke

unread,
Jun 3, 2011, 6:42:04 AM6/3/11
to Ariadne
On Jun 3, 11:54 am, Michele <fiaschett...@gmail.com> wrote:
> > <pinp>
> >    $client = ar('http')->client();
> >    $result = $client->get( 'http://..../');
> >    echo '<pre>';
> >    echo $client->responseHeaders;
> >    echo '</pre>';
> >    echo $result;
> > </pinp>
>
> > That should give you the complete result and the headers.
>
> No results here, I get only the string  'array' on my page

Sorry, it should have been var_dump($result); instead of echo...
Reply all
Reply to author
Forward
0 new messages