title: file_get_contents('php://input') is always empty
body: <p>I'm trying to get the data of a POST request sent via cURL. I'm using <code>file_get_contents('php://input')</code> but it's always empty. What am I missing?</p>
  
  <h3>My script</h3>
  
  <pre><code>&lt;?php
  
  $data_string = json_encode([ "foo" =&gt; 123 ]);
  
  
  $ch = curl_init('http://httpbin.org/post');
  
  #
  # Debugging
  #
  
  # Send traffic through proxy
  #curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
  
  $stderr = fopen('php://temp', 'w+');
  curl_setopt($ch, CURLOPT_STDERR, $stderr);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  
  #
  # Send request
  #
  
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Content-Type: application/json',
      'Content-Length: ' . strlen($data_string)
  ]);
  $result = curl_exec($ch);
  
  echo "\nRESULT:\n$result";
  
  #
  # Output debugging
  #
  
  rewind($stderr);
  $stderrLog = stream_get_contents($stderr);
  
  echo "\nDEBUG:\n$stderrLog\n";
  
  echo "\nSETTINGS:\nallow_url_fopen: ", ini_get('allow_url_fopen'), "\n";
  
  $body = file_get_contents('php://input');
  echo "\nBODY:\n$body\n";
  </code></pre>
  
  <h3>Script result</h3>
  
  <pre><code>RESULT:
  {
    "args": {},
    "data": "{\"foo\":123}",
    "files": {},
    "form": {},
    "headers": {
      "Accept": "*/*",
      "Connection": "close",
      "Content-Length": "11",
      "Content-Type": "application/json",
      "Host": "httpbin.org"
    },
    "json": {
      "foo": 123
    },
    "origin": "65.199.22.138",
    "url": "http://httpbin.org/post"
  }
  
  DEBUG:
  *   Trying 23.21.55.239...
  * TCP_NODELAY set
  * Connected to httpbin.org (23.21.55.239) port 80 (#0)
  &gt; POST /post HTTP/1.1
  Host: httpbin.org
  Accept: */*
  Content-Type: application/json
  Content-Length: 11
  
  * upload completely sent off: 11 out of 11 bytes
  &lt; HTTP/1.1 200 OK
  &lt; Connection: keep-alive
  &lt; Server: meinheld/0.6.1
  &lt; Date: Wed, 28 Feb 2018 18:08:13 GMT
  &lt; Content-Type: application/json
  &lt; Access-Control-Allow-Origin: *
  &lt; Access-Control-Allow-Credentials: true
  &lt; X-Powered-By: Flask
  &lt; X-Processed-Time: 0
  &lt; Content-Length: 343
  &lt; Via: 1.1 vegur
  &lt;
  * Connection #0 to host httpbin.org left intact
  
  
  SETTINGS:
  allow_url_fopen: 1
  
  BODY:
  </code></pre>
  
  <h3>Additional info</h3>
  
  <ul>
  <li>PHP version: 7.2.2</li>
  <li>PHP error log is receiving errors but nothing from this code</li>
  <li>I've verified via mitmproxy that the request is sending JSON data</li>
  <li>allow_url_fopen is set to true (see script)</li>
  </ul>