FileRepo: create output buffer and set ob_implicit_flush for file streaming
authorZhuyifei1999 <zhuyifei1999@gmail.com>
Wed, 9 Aug 2017 09:51:41 +0000 (09:51 +0000)
committerZhuyifei1999 <zhuyifei1999@gmail.com>
Wed, 9 Aug 2017 09:52:10 +0000 (09:52 +0000)
HHVM does not flush automatically until the output is done, unless
flush() is called. We create an output buffer so that PHP is aware
of the amount of data in the output buffer; we set ob_implicit_flush
so that, when output buffer is full and being flushed, it flushes
HHVM's buffer as well, emptying the OOM culprit.

Bug: T172851
Change-Id: I34dd1034590779ab51f197762177ad03291e3581

includes/filerepo/FileRepo.php

index f89d96b..dc36e50 100644 (file)
@@ -1602,9 +1602,15 @@ class FileRepo {
                $path = $this->resolveToStoragePath( $virtualUrl );
                $params = [ 'src' => $path, 'headers' => $headers, 'options' => $optHeaders ];
 
+               // T172851: HHVM does not flush the output properly, causing OOM
+               ob_start( NULL, 1048576 );
+               ob_implicit_flush( true );
+
                $status = $this->newGood();
                $status->merge( $this->backend->streamFile( $params ) );
 
+               ob_end_flush();
+
                return $status;
        }