2

I'm trying to write an API that accepts PUT, PATCH and DELETE request methods and I was able to do so, but I was running into an issue where reading from php://input is extremely slow. Parsing a request with a 970k gif file takes 10-12 seconds and from the logging I added, all that time is spent reading from php://input

$stream = fopen('php://input', 'r');
// Log stream opened
$raw_data = "";
while(!feof($stream)) {
    $raw_data .= fread($stream, $headers['content-length']);
}
// Log stream read
fclose($stream);

The time between those two log entries, as I said, is 10-12 seconds. What am I doing wrong? Is there a php setting somewhere I need to change?

Thanks

SynackSA
  • 855
  • 1
  • 12
  • 35
  • This has been solved (but not fixed). Seems to be an issue surrounding my development environment (vagrant). When I put this on the QA server to test, it ran extremely quickly. – SynackSA Mar 22 '17 at 17:52
  • See https://stackoverflow.com/a/14390106/1676044. If the content-length header in the request exceeds the actual content length, PHP will wait ten seconds. – Kevin Borders Oct 27 '17 at 05:35
  • Possible duplicate of [PHP file\_get\_contents('php://input') very slow](https://stackoverflow.com/questions/14295901/php-file-get-contentsphp-input-very-slow) – Kevin Borders Oct 27 '17 at 05:36

0 Answers0