title: PHP/Curl - Loop & POST buffer not clearing
body: <p>I'm using cUrl to POST to a web page (not local) and then return the html. </p>
  
  <p>I need to do this multiple times, so the cUrl code is in a while loop. Here's the weird thing: it works as expected the first time, but doesn't seem to clear the POST buffer everytime there after. (I do close_curl($ch). And all the data passed through POST is correct.)</p>
  
  <p>For instance, one of the text fields should be (and, the first time, is) pass "ANY". But the second time it is pass "ANY, ANY".</p>
  
  <p><strong>Am I correct that this problems lies in an uncleared POST buffer? How can I fix it?</strong></p>
  
  <hr>
  
  <p>SORRY: Here's a shortened version of the code...</p>
  
  <pre><code>$someResults = mysql_query($someSQL);
  
  while($record = mysql_fetch_array($alertResults)){
      $url = "http://something.com/searchResults.asp";
      $someV = "Hi";
  
      $fields = array(
          //date to post.
      );     
  
      foreach($fields as $key=&gt;$value){ 
          $fields_string .= $key .'='. $value . '&amp;'; 
      }
      rtrim($fields_string,'&amp;');
      $ch = curl_init();
      $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
      curl_setopt($ch,CURLOPT_USERAGENT, $userAgent);
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_POST,count($fields));
      curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
      curl_setopt($ch, CURLOPT_FAILONERROR, true);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
      ob_start(); 
      $html = curl_exec($ch);
      curl_close($ch);
  
      $dom = new DOMDocument();
      @$dom-&gt;loadHTML($html);
      $xpath = new DOMXPath($dom);
      $resultTable = $xpath-&gt;evaluate("/html/body//table"); 
  }
  </code></pre>
  
  <p>And, when I do this, the first time through the loop $resultTable has 60 items in it. But everytime there after (using the same url) it has 0 items. And I'm pretty sure it's because the POST buffer isn't cleared and things get posted ontop of previous POST data.</p>
  
  <p><strong>How can I clear the POST data each time through the loop?</strong></p>