title: 502 bad gateway: php://input
body: <p>In a php file I am reading the input stream which contains an image. </p>
  
  <pre><code>$incomingData = file_get_contents('php://input');
  $fh = fopen($uploadPath, 'w');
  fwrite($fh, $incomingData);
  fclose($fh);
  </code></pre>
  
  <p>For small images this works just fine, for bigger ones which takes longer than 15 seconds or so i get a 502 bad gateway response.</p>
  
  <p>The apache error log is saying:</p>
  
  <p>child pid 1492 exit signal Segmentation fault (11)</p>
  
  <p>I tried this but that did not work.</p>
  
  <pre><code> ini_set('default_socket_timeout', 120);
  </code></pre>
  
  <p>But I am not sure of its a time out.</p>
  
  <p>edit// CODE:
      
  
  <pre><code>$uploadFilename = time();
  $uploadPath = '/path/melvin.jpg';
  
  $fhSrc = fopen('php://input', 'r');
  
  // Valid data?
  if($fhSrc) {
  
      $fhDst = fopen($uploadPath, 'w');
  
      while (($data = fread($fhSrc, 1024)) !== FALSE) {
          fwrite($fhDst, $data);
      }
  
      fclose($fhSrc);
      fclose($fhDst);
  
  }
  
  echo 'ok';
  </code></pre>
  
  <p>RAW HEADERS:</p>
  
  <pre><code>POST /test.php HTTP/1.1
  Host: hi.com
  User-Agent: secret/1.0 (unknown, iPhone OS 5.0.1, iPhone, Scale/2.000000)
  Accept: */*
  Accept-Language: nl, en, fr, de, ja, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8
  Accept-Encoding: gzip
  Settings: {SOMEJSON}
  Content-Type: application/x-www-form-urlencoded
  Cookie: CAKEPHP=2b82f748fb3a64063b2e3be9bdec5c11
  Connection: keep-alive
  Transfer-Encoding: Chunked
  Pragma: no-cache
  Cache-Control: no-cache
  
  and here in the boy the Big image
  </code></pre>