From 45c6e888ebda16e446d36d27d47df974e3152190 Mon Sep 17 00:00:00 2001 From: Sebastian Kostka Date: Mon, 12 Jun 2017 09:44:50 +0200 Subject: [PATCH] Work around 4GB file size limit at 32 Bit systems (#74) Closes #77 --- lib/Sapi.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Sapi.php b/lib/Sapi.php index dd49913..a93ea1e 100644 --- a/lib/Sapi.php +++ b/lib/Sapi.php @@ -88,7 +88,15 @@ static function sendResponse(ResponseInterface $response) { if ($contentLength !== null) { $output = fopen('php://output', 'wb'); if (is_resource($body) && get_resource_type($body) == 'stream') { - stream_copy_to_stream($body, $output, (int)$contentLength); + if (PHP_INT_SIZE !== 4){ + // use the dedicated function on 64 Bit systems + stream_copy_to_stream($body, $output, $contentLength); + } else { + // workaround for 32 Bit systems to avoid stream_copy_to_stream + while (!feof($body)) { + fwrite($output, fread($body, 8192)); + } + } } else { fwrite($output, $body, (int)$contentLength); }