title: PHP HTTP POST fails when cURL data > 1024
body: <p><strong>Note: solution at the end</strong></p>
  
  <p>If I attempt to do a HTTP POST of over 1024 characters, it fails. Why? Here is a minimal example:</p>
  
  <p>recipient.php:</p>
  
  <pre><code>&lt;?php
  if (strlen(file_get_contents('php://input')) &gt; 1000
      || strlen($HTTP_RAW_POST_DATA) &gt; 1000) {
   echo "This was a triumph.";
  }
  ?&gt;
  </code></pre>
  
  <p>sender.php:</p>
  
  <pre><code>&lt;?php
  function try_to_post($char_count) {
   $url = 'http://gpx3quaa.joyent.us/test/recipient.php';
   $post_data = str_repeat('x', $char_count);
   $c = curl_init();
   curl_setopt_array($c,
                      array(  CURLOPT_URL =&gt; $url,
                              CURLOPT_HEADER =&gt; false,
                              CURLOPT_CONNECTTIMEOUT =&gt; 999,
                              CURLOPT_RETURNTRANSFER =&gt; true,
                              CURLOPT_POST =&gt; 1,
                              CURLOPT_POSTFIELDS =&gt; $post_data
                      )
   );
   $result = curl_exec($c);
   echo "{$result}\n";
   curl_close($c);
  }
  
  for ($i=1020;$i&lt;1030;$i++) {
   echo "Trying {$i} - ";
   try_to_post($i);
  }
  ?&gt;
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Trying 1020 - This was a triumph.
  Trying 1021 - This was a triumph.
  Trying 1022 - This was a triumph.
  Trying 1023 - This was a triumph.
  Trying 1024 - This was a triumph.
  Trying 1025 - 
  Trying 1026 - 
  Trying 1027 - 
  Trying 1028 - 
  Trying 1029 - 
  </code></pre>
  
  <p>configuration:</p>
  
  <pre><code>PHP Version 5.2.6
  libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
  lighttpd-1.4.19
  </code></pre>
  
  <p><strong>Solution</strong></p>
  
  <p>Add the following option for cURL:</p>
  
  <pre><code>curl_setopt($ch,CURLOPT_HTTPHEADER,array("Expect:"));
  </code></pre>
  
  <p>The reason seems to be that any POST over 1024 character causes the "Expect: 100-continue" HTTP header to be sent, and Lighttpd 1.4.* does not support it. I found a ticket for it: <a href="http://redmine.lighttpd.net/issues/show/1017" rel="noreferrer">http://redmine.lighttpd.net/issues/show/1017</a></p>
  
  <p>They say it works in 1.5.</p>