zfeeder / fopen/cURL issues
Posted by: argjamesi
Posted on: 2005-12-29 22:01:00
Boy do I need help...
zfeeder is an RSS parser/aggregator that I use on my site (argn.com) to display the last 5 entries at three different bogs/forums I check regularly. It's super easy to set up and maintain, provided the fopen command is available to get URLs from outside sources. Because of security issues, it is not here at DH. I'm fine with that.
However, after reading multiple sources of documentation about cURL and how to work around the fact that I cannot use fopen for URLs, I'm at a loss as to why my feeds still aren't streaming in. One of the only places where fopen attempts to read from an external URL (and not a filename on my own site) is in a function PHP page, and I've changed this code:
function fetchFeed($from, $to)
{
@ini_set("user_agent","zfeeder/".ZF_VER." (http://zvonnews.sf.net)");
@$fp = fopen($from, "r");
$data = '';
while (true) {
@$datas = fread($fp, 4096);
if (strlen($datas) == 0) {
break;
}
$data .= $datas;
}
@fclose($fp);
if ($data != '') {
$fp = fopen($to, "w");
fwrite($fp, $data);
fclose($fp);
@chmod($to, 0766);
return($from . " - cached <br />n");
} else {
return($from . " - NOT cached; check connection <br />n");
}
}
with this updated version (using the cURL commands):
function fetchFeed($from, $to)
{
@ini_set("user_agent","zfeeder/".ZF_VER." (http://zvonnews.sf.net)");
$curl_handle = curl_init();
curl_setopt ($curl_handle, CURLOPT_URL, $from);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);
$fp = curl_exec($curl_handle);
curl_close($curl_handle);
$data = '';
while (true) {
@$datas = fread($fp, 4096);
if (strlen($datas) == 0){
break;
}
$data .= $datas;
}
if ($data != '') {
$fp = fopen($to, "w");
fwrite($fp, $data);
fclose($fp);
@chmod($to, 0766);
return($from . " - cached <br />n");
} else {
return($from . " - NOT cached; check connection <br />n");
}
}
Now, from where I stand, that shoudl work. However, like I said, I am still experiencing connection problems. Can anyone help me with this problem?
jamesi