[pmwiki-users] Keeping recipes up to date
marc
gmane at auxbuss.com
Thu Feb 15 11:06:43 CST 2007
Patrick R. Michaud said...
> On Thu, Feb 15, 2007 at 04:01:34PM -0000, marc wrote:
> > Patrick R. Michaud said...
> > > On Thu, Feb 15, 2007 at 03:08:20PM -0000, marc wrote:
> > > > Ah well, another customised recipe for my collection :-| Thank heavens
> > > > for Subversion.
> > >
> > > Well, I think we can avoid the need for customized recipes.
> > > ...
> > > Then a site could supply a custom setting for $UrlFopen that
> > > does the equivalent of fopen with allow_url_fopen enabled.
> > > Then any sites that have allow_url_fopen disabled can just
> > > include_once('cookbook/urlfopen.php') to load a custom
> > > function for url-based file retrievals.
> >
> > Looks okay to me.
>
> Looking a little further at curl, it looks as though we'd
> be better off having a function that returns the entire file,
> as opposed to a file handle.
Ah, I misread your code.
> (In other words, I'm not sure
> how to get curl to act like a filehandle.)
>
> So, perhaps something like...? (I've never used curl in PHP before.)
>
> function curl_get_contents($url) {
> $ch = curl_init($url);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_HEADER, 0);
> $str = curl_exec($ch);
> curl_close($ch);
> return $str;
> }
> SDV($UrlFileFunction, 'curl_get_contents');
That's pretty much as I do (in a class):
function load($url) {
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_HEADER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
if (! $this->pageText = curl_exec($ch)) {
PmWikiError::getInstance()->postError(
'Class '. get_class() .": $url :\\\\\n".curl_error($ch));
curl_close($ch);
return false;
}
curl_close($ch);
return true;
}
and
function getPageText() {return $this->pageText;}
function getPageTextArray() {return explode ("\n",$this->pageText);}
--
Cheers,
Marc
More information about the pmwiki-users
mailing list