View Full Version : Will this curl snippet work with most web host php configs?

05-15-2008, 10:35 PM
if(!file_exists($file) || filemtime($file) < time() - 3600)
$ch = curl_init('http://www.mydomain.com/rss?p=' . urlencode($rpl) . '&u=' . urlencode($units['date']));
@curl_setopt($ch, CURLOPT_HEADER, 0);
//@curl_setopt($ch, CURLOPT_MUTE, 1);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$str = @curl_exec($ch);
$fp = @fopen($file,'w');

$this->data = @file_get_contents($file);

I'm creating a version of this script that does not use fopen. Can someone please help modify?

05-15-2008, 10:59 PM
Sure.. if they have CURL installed. If you have PHP 5(you can find versions for PHP 4 too) you will be able to use file_put_contents() (http://php.net/file_put_contents) instead of fopen() (http://php.net/fopen), fwrite() (http://php.net/fwrite), and fclose() (http://php.net/fclose). Your error catching is pretty lacking. Are you taking into account that any or all of that could fail and you you not know why?