Skip to content

Commit 49adbb9

Browse files
Merge branch '5.4' into 6.2
* 5.4: [Console] Fix computing column width containing multibyte chars [Messenger] Fix deprecation layer of RedeliveryStamp [Mime] Form field values with integer keys not resolved correctly [Messenger] [Redis] Fixed problem where worker stops handling messages on first empty message [PHPUnitBridge] Fix PHPUnit 10.1 compatibility [VarDumper] Make the server TCP connection sync [Messenger] Fix warning message on failed messenger show command [Mailer] [Mailjet] Use body MessageID instead of X-MJ-Request-GUID [HttpFoundation] Fix BinaryFileResponse [Form] fix merge [HttpFoundation] Fix memory limit problems in BinaryFileResponse [PropertyAccess] Readonly properties must have no PropertyWriteInfo [Form] Cast choices value callback result to string [Serializer] Unexpected value should throw UnexpectedValueException [ErrorHandler] Don't throw deprecations for HttplugClient [Serializer] Fix denormalization of object with typed constructor arg (not castable) and with COLLECT_DENORMALIZATION_ERRORS Avoid leading .. for temporary files from Filesystem recursive remove
2 parents 511a524 + af9fbb3 commit 49adbb9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

BinaryFileResponse.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class BinaryFileResponse extends Response
3434
protected $offset = 0;
3535
protected $maxlen = -1;
3636
protected $deleteFileAfterSend = false;
37-
protected $chunkSize = 8 * 1024;
37+
protected $chunkSize = 16 * 1024;
3838

3939
/**
4040
* @param \SplFileInfo|string $file The file to stream
@@ -240,7 +240,7 @@ public function prepare(Request $request): static
240240
$range = $request->headers->get('Range');
241241

242242
if (str_starts_with($range, 'bytes=')) {
243-
[$start, $end] = explode('-', substr($range, 6), 2) + [0];
243+
[$start, $end] = explode('-', substr($range, 6), 2) + [1 => 0];
244244

245245
$end = ('' === $end) ? $fileSize - 1 : (int) $end;
246246

@@ -311,14 +311,21 @@ public function sendContent(): static
311311

312312
$length = $this->maxlen;
313313
while ($length && !feof($file)) {
314-
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
315-
$length -= $read;
314+
$read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length;
316315

317-
stream_copy_to_stream($file, $out, $read);
318-
319-
if (connection_aborted()) {
316+
if (false === $data = fread($file, $read)) {
320317
break;
321318
}
319+
while ('' !== $data) {
320+
$read = fwrite($out, $data);
321+
if (false === $read || connection_aborted()) {
322+
break;
323+
}
324+
if (0 < $length) {
325+
$length -= $read;
326+
}
327+
$data = substr($data, $read);
328+
}
322329
}
323330

324331
fclose($out);

0 commit comments

Comments
 (0)