title: Curl returns successfully but shows 500 error, Internal server Error
body: <p>I am accessing a web service using curl, but at times I get response but other times it fails with an Internal Server Error even though I actually receive the expected xml file. What could the problem be?</p>
  
  <pre><code>$header = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "Content-length: ".strlen($send),
                  );
  
              $URL = 'https:ip:port/xxxxx';
  
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
              curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
              curl_setopt($ch, CURLOPT_TIMEOUT, 120);
              curl_setopt($ch, CURLOPT_URL, $URL );
              curl_setopt($ch, CURLOPT_POST, true );
              curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //array('Content-Type: text/xml'));
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
              curl_setopt($ch, CURLOPT_POSTFIELDS, $send );
              //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
  try {
                  $result = curl_exec($ch);        
                  curl_close($ch);
                  $f = fopen("./Response.xml", "w");
                  fwrite($f, $result);
                  fclose($f);           
              } 
              catch (Exception $e) {
                  $payments = "&lt;DIV class = 'alert alert-danger'&gt;Failed Transaction. Please try again&lt;/DIV&gt;";
                       $error = Date("Y-m-d h:i:s")."\nError Number:".curl_errno($soap_do)."\n";
                       $error .=  "Error String:".curl_error($ch)."\n Matrucule: ".$matricule."\n------------------------\n";
                       $f = fopen("./Payment_Error_Log.txt", "w");
                       fwrite($f, $error);
                       fclose($f);
              }
  </code></pre>