Re: XML_RSS time out question
| From: | Jesus M. Castagnetto | Date: | Mon, 06 May 2002 22:31:00 +0000 |
| Subject: | Re: XML_RSS time out question | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1348@lists.php.net to get a copy of this message | ||
It does not look OK. Perhaps you missed something when using the example from
fsockopen() as a beggining point
--- Luc Saint-Elie <luc@saint-elie.com> wrote:
> Thanks Jesus,
>
> Please would the following be correct ?
>
> $so = fsockopen ("www.mypartnersite.com", 80, $errno, $errstr, 10);
> if ($so){
If you got a resource in $so, then you can start reading from it
> $fo = @fopen
> ("http://www.mypartnersite.com/backend.php",
> "r");
This is redundant, why would you use both. Either use the fopen() w/ the URL
(taking advantage of the http wrapper) or use fsockopen() not both
The rest of the code will not work, as $fo is a resource, and does not contain
the data in the URL above.
You will need to loop to accumulate the data:
while ($r = fread($fo, 1024))
$rss_data .= $r;
and then pass $rss_data in the class constructor, etc. You can us fgets() too
if you are more used to using that from C. Just pick the appropriate size of
the chunks you want to read.
> if($fo){
> require_once "XML/RSS.php";
> $rss =& new XML_RSS($fo);
> $rss->parse();
> $items = $rss->getItems();
> $smarty->assign('items', $items);
> }
> }
> }
>
Although if you are not using the error msgs, and not worrying about
blocking/non-blocking, you can simplify the code to use:
$fo = implode("",file($url));
by making use of the HTTP wrappers, but that does not allow you a lot of
control in the timeout, etc.. The fsockopen() is more flexible in any case.
Just don't forget to close the socket at the end (fclose())
>
> Luc
>
>
> At 18:07 05/05/2002 -0700, Jesus M. Castagnetto wrote:
> >To avoid this problem, you could open a socket connection and then get the
> >data
> >from the remote server. Then pass the data to XML_RSS. I am not sure if it
> >is a
> >good idea to include timeout/socket connections in that class, which is
> >intended for parsing RSS.
> >
> >HTH
> >
> >--- Luc Saint-Elie <luc@saint-elie.com> wrote:
> > > Hello,
> > >
> > > I'm a happy user of XML_RSS except on one point :
> > >
> > > require_once "XML/RSS.php";
> > > $rss =& new
> > > XML_RSS("http://www.mypartnersite.com/backend.php");
> > > $rss->parse();
> > > $items = $rss->getItems();..and so on....
> > >
> > > If http://www.mypartnersite.com is out, my own site
> > > is stuck
> > >
> > > Is there away to set some kind of time out ?
> > >
> > > Thanks in advance
> > >
> > > Luc
>
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
=====
--- Jesus M. Castagnetto (jcastagnetto@yahoo.com)
Research:
http://metallo.scripps.edu/
Personal: http://www.castagnetto.org/
__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com