View Full Version : Problem with cURL/PHP

08-18-2007, 07:04 PM
Hi, I am facing a strange problem with curl. I am fetching two different URLs on a single page with curl in two different functions. The 1st function returns proper data but the 2nd doesn't return anything. If I comment out the 1st function then the 2nd one works nicely. I have been pulling out my hair for over 5 hours now and I need your help...

$feed_uri = 'http://www.my_server.com/mk/favicons/filename.php?feed='.urlencode('http://earthquake.usgs.gov/eqcenter/catalogs/eqs7day-M2.5.xml');
$favicon = getFaviconName($feed_uri); //This will return the favicon address for the feed. Something like http://www.santabanta.com/favicon.ico This function is working fine and returns the url properly.

preg_match('/[^.]+$/', $favicon, $matches);
$mime = 'bmp';
if ($matches[0] == 'ico') {
$mime = 'x-icon';
} else {
$mime = $matches[0];
header('Content-type: image/'.$mime);

echo renderFavicon($favicon); //This will fetch the image and then spit it out to the browser. This is not working, it just renders nothing. If I comment out the getFaviconName function call from above and directly pass the icon url then it works fine.


function getFaviconName($uri)
$fv = curl_init();
curl_setopt($fv, CURLOPT_URL, $uri);
curl_setopt($fv, CURLOPT_HEADER, false);
curl_setopt($fv, CURLOPT_RETURNTRANSFER, true);
$ficon = curl_exec($fv);
return $ficon;

function renderFavicon($fav) {
//$favicon = 'http://www.santabanta.com/favicon.ico';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fav);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$icon = curl_exec($ch);
echo $icon;
return $icon;


08-18-2007, 07:17 PM
Wouldn't this be easier with file_get_contents()? You probably don't need curl to perform the first function either.