title: fopen(): SSL: Connection reset by peer error in php
body: <p>I'm trying to download a report from my bing ads account and i'm encountering the following errors:
  Warning: fopen(): SSL: Connection reset by peer in xxxx...
  Warning: fopen(): Failed to enable crypto in xxx...</p>
  
  <pre><code>      function PollGenerateReport($proxy, $reportRequestId)
        {
           // Set the request information.
  
           $request = new PollGenerateReportRequest();
           $request-&gt;ReportRequestId = $reportRequestId;
  
           return $proxy-&gt;GetService()-&gt;PollGenerateReport($request)-&gt;ReportRequestStatus;
           return $proxy-&gt;GetService()-&gt;PollGenerateReport($request)&gt;ReportRequestStatus;
         }
  
        // Using the URL that the PollGenerateReport operation returned,
        // send an HTTP request to get the report and write it to the specified
        // ZIP file.
        function DownloadFile($reportDownloadUrl, $downloadPath)
        {
            if (!$reader = fopen($reportDownloadUrl, 'rb'))
             {
                 throw new Exception("Failed to open URL " . $reportDownloadUrl . ".");
             }
             if (!$writer = fopen($downloadPath, 'wb'))
             {
                 fclose($reader);
                 throw new Exception("Failed to create ZIP file " . $downloadPath . ".");
              }
              $bufferSize = 100 * 1024;
  
              while (!feof($reader))
              {
                  if (false === ($buffer = fread       ($reader, $bufferSize)))
                   {
                      fclose($reader);
                      fclose($writer);
                      throw new Exception("Read operation from URL failed.");
                   }
                   if (fwrite($writer, $buffer) === false)
                   {
                       fclose($reader);
                       fclose($writer);
                       $exception = new Exception("Write operation to ZIP file failed.");
                   }
                }
                   fclose($reader);
                   fflush($writer);
                   fclose($writer);
           }
  </code></pre>
  
  <p>Since i'm a newbie to php, i'm asking for any assistance/tipps on how to convert the fopen() function (which from research seems to be the problem here) to curl. I'm using the bing API to download the report and running the script on a server.
  Thanks.</p>