1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 19:23:22 +02:00

Avoid duplicate fstat() for includes

By adding a flag to avoid forced fstat for includes. The two fstats
will happen back to back and we don't care about a possible
invalidation.

I was hoping to move this higher up in the stack and make the
ISREG check somewhere in fsizer of fixup, but this doesn't really
seem to be possible. E.g. an FP stdin handle will not be a regular
file but of course needs to be allowed. Additionally custom stream
wrappers may not implement this functionality.
This commit is contained in:
Nikita Popov
2019-07-17 14:43:53 +02:00
parent b30e4a5aa6
commit 07a4d134ab
+6 -1
View File
@@ -128,6 +128,7 @@ typedef struct {
unsigned is_pipe:1; /* don't try and seek */
unsigned cached_fstat:1; /* sb is valid */
unsigned is_pipe_blocking:1; /* allow blocking read() on pipes, currently Windows only */
unsigned no_forced_fstat:1; /* Use fstat cache even if forced */
unsigned _reserved:28;
int lock_flag; /* stores the lock state */
@@ -152,7 +153,7 @@ typedef struct {
static int do_fstat(php_stdio_stream_data *d, int force)
{
if (!d->cached_fstat || force) {
if (!d->cached_fstat || (force && !d->no_forced_fstat)) {
int fd;
int r;
@@ -1079,6 +1080,10 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
php_stream_close(ret);
return NULL;
}
/* Make sure the fstat result is reused when we later try to get the
* file size. */
self->no_forced_fstat = 1;
}
if (options & STREAM_USE_BLOCKING_PIPE) {