curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
should be:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
therefore, curl knows that it should return data, not output it back.
Also, sometimes you need to do one more job to get the curl accepted SSL certificates:
Using cURL in PHP to access secure HTTPS sites (SSL / TLS)
EDIT:
Given your use, you should also set CURLOPT_HEADER to false, as Alix Axel recommended.
SSL , , , , SSL, Alix, , , , , CURL .