title: php cURL script run twice when printing return string
body: <p>I have the following script. In the remote php script a record is added to a database table.
  When I leave the last line (print $html;) in this script, 2 records are added!</p>
  
  <p>When I leave out that line only one record is added. But then I don't have any output, obviously.</p>
  
  <p>If I write the output to a file, only one record is added. The output is a html page.</p>
  
  <pre><code>&lt;?php
    $ch = curl_init();
  
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, 'http://somedomain.nl/some.php?PARAMS=blabla');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  
    // cookie settings
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'some.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'some.txt');
  
    // set data to be posted
    curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
  
    // perform the request
    $html = curl_exec($ch);
  
    // close the connection
    curl_close($ch);
  
    print $html;
  ?&gt;
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Gr. Han</p>
  
  <p>/<em>*</em>*  Update</p>
  
  <pre><code>&lt;select class="p_ssyskey_mke" name=P_SSYSKEY_MKE onchange="MerkSubmitP()"&gt;
    &lt;option value=""&gt;selecteer een merk&lt;/option&gt;
    &lt;option value="A0001E2Q"&gt;Subaru&lt;/option&gt;
    &lt;option selected value="A0001E2S"&gt;Toyota&lt;/option&gt;
    &lt;option value="A0001E2T"&gt;Volkswagen&lt;/option&gt;
  &lt;/select&gt; 
  </code></pre>
  
  <p>This is a snippet of $html, the entire page is rather large. 
  Printing a substring of the html reveals that the script will run a second time when the '
  
  <p>@Poonam: When I print $html after ob_clean_end() again a second record is added.</p>
  
  <p>For now I have implemented a very crude workaround. Since the record has a timestamp I prevent a second record to be added if the last one is not at least 1 second old. I hate it, but for now it works. </p>
  
  <p>Gr. Han</p>
  
  <p>/<em>*</em>*  Update</p>
  
  <p>This problem doesn't come from cURL, trying the same thing with file_get_contents does the same thing.</p>
  
  <p>Maybe the cause is in the mod_rewrite I'm using. </p>
  
  <p>Gr. Han</p>
  
  <p>/<em>*</em>*  Update</p>
  
  <p>Most probably the mod_rewrite. When using direct URL's instead of going through the rewrite-rules it behaves as expected. </p>
  
  <p>these is the rewrite rules I'm using:</p>
  
  <pre><code>RewriteEngine On
  RewriteRule ^zoek/(.*)$ parts.php?PARAMS=$1 [L]
  </code></pre>
  
  <p>Parts.php is the script posted above.</p>
  
  <p>Gr. Han</p>