From 809a639b6a54bd1f63e9e5437509d7b0d3898fdd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Feb 2022 22:07:44 +0100 Subject: [PATCH] ext/standard/file: disable the read buffer in file_get_contents() The read buffer is useless here, it only hurts performance. --- ext/standard/file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/standard/file.c b/ext/standard/file.c index 628b8dc8f0fe1..7a6554ac1d9d9 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -566,6 +566,12 @@ PHP_FUNCTION(file_get_contents) RETURN_FALSE; } + /* disabling the read buffer allows doing the whole transfer + in just one read() system call */ + if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) { + php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL); + } + if (offset != 0 && php_stream_seek(stream, offset, ((offset > 0) ? SEEK_SET : SEEK_END)) < 0) { php_error_docref(NULL, E_WARNING, "Failed to seek to position " ZEND_LONG_FMT " in the stream", offset); php_stream_close(stream);