Here is a simpler code for the same:
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
where $fp is a file handle to output errors. For example:
$fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
( Read on http://curl.haxx.se/mail/curlphp-2008-03/0064.html )