Skip to content

Commit 6beee1a

Browse files
MaxKellermanncmb69
authored andcommitted
Disable the read buffer in file_get_contents()
The read buffer is useless here, it only hurts performance. Closes GH-8547.
1 parent 1f4830f commit 6beee1a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ext/standard/file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ PHP_FUNCTION(file_get_contents)
566566
RETURN_FALSE;
567567
}
568568

569+
/* disabling the read buffer allows doing the whole transfer
570+
in just one read() system call */
571+
if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) {
572+
php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
573+
}
574+
569575
if (offset != 0 && php_stream_seek(stream, offset, ((offset > 0) ? SEEK_SET : SEEK_END)) < 0) {
570576
php_error_docref(NULL, E_WARNING, "Failed to seek to position " ZEND_LONG_FMT " in the stream", offset);
571577
php_stream_close(stream);

0 commit comments

Comments
 (0)