title: How to pass POST data to the PHP-CGI?
body: <p><strong>Update:</strong></p>
  
  <p>In a fit of desperation, I did the following in a shell:</p>
  
  <pre><code>REDIRECT_STATUS=true
  SCRIPT_FILENAME=/var/www/...
  REQUEST_METHOD=POST
  GATEWAY_INTERFACE=CGI/1.1
  export REDIRECT_STATUS
  export SCRIPT_FILENAME
  export REQUEST_METHOD
  export GATEWAY_INTERFACE
  echo "test=1" | php-cgi
  </code></pre>
  
  <p>...and STILL no <code>$_POST</code> variables are showing up in the output of this:</p>
  
  <pre><code>&lt;?php var_dump($_POST); ?&gt;
  </code></pre>
  
  <hr>
  
  <p>I am trying to create a small webserver that interfaces with the <code>php-cgi</code> binary. However, things aren't going so well. The <code>php-cgi</code> binary correctly handles GET requests. When it comes to POST requests, the <code>$_POST</code> array is empty, even when things are getting POSTed.</p>
  
  <p>I've checked the HTTP headers being fed into the <code>php-cgi</code> binary and they do indeed include the POST data and the <code>Content-type: application/x-www-form-urlencoded</code> header.</p>
  
  <p>What could be keeping the <code>php-cgi</code> binary from seeing that there's POST data included in the request?</p>
  
  <hr>
  
  <p>I'm making progress, I've dug up some stuff from the <a href="http://svn.php.net/repository/php/php-src/branches/PHP_5_2/" rel="noreferrer">PHP source code</a>:</p>
  
  <ul>
  <li><p><a href="http://svn.php.net/repository/php/php-src/branches/PHP_5_2/sapi/cgi/" rel="noreferrer">/sapi/cgi/cgi_main.c</a>:</p>
  
  <blockquote>
    <p><code>468: static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)</code></p>
  </blockquote></li>
  </ul>
  
  <p>(I have no idea where this function is invoked from.)</p>
  
  <hr>
  
  <p>After reading the answer below, I tried:</p>
  
  <pre><code>&lt;?php
  
  var_dump($HTTP_RAW_POST_DATA);
  
  ?&gt;
  </code></pre>
  
  <p>...which yielded the output:</p>
  
  <pre><code>NULL
  </code></pre>
  
  <p>...indicating that something even stranger is at work here.</p>
  
  <hr>
  
  <p>I'm getting closer... I found this function in <a href="http://svn.php.net/repository/php/php-src/branches/PHP_5_2/main/php_content_types.c" rel="noreferrer">/main/php_content_types.c</a>:</p>
  
  <blockquote>
    <p>SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)</p>
  </blockquote>
  
  <p>...and it seems to be the code that processes POST requests.</p>