I removed some unnecessary "stuff" from your function, as in unnecessary for my purpose:
$key = '9c85694a-6b88-427b-a8e4-62d5366aa6a9'; //Your API Key
$secret = 'GD9heuq1k0MO49dKCFJawQLNMY2izza+wTjAe/GkKf+2KnaZC5Zf/qUsiQSWNIN5ltwtYahygZb7i2UI2I48TQ=='; //Your API Secret
$req['nonce'] = $GLOBALS['nonce']++; //Incriment the Global Nonce (Allows for multiple polls per second)
$post_data = http_build_query($req, '', '&'); // generate the POST data string
$prefix = $path."\0";
// generate the extra headers
$headers = array(
'Rest-Key: '.$key,
'Rest-Sign: '.base64_encode(hash_hmac('sha512', $prefix.$post_data, base64_decode($secret), true)),
);
$ch = null;
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; GOXBOT; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_URL, 'https://data.mtgox.com/api/2/'.$path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
writeInc($GLOBALS['nonce']);
return curl_exec($ch);
}