Today and colleagues to discuss the role of the Fflush function, the PHP file system function should be built on the system's standard I/O library, so, arbitrarily think that the role of fflush is to brush out the standard I/O library buffer, equivalent to the standard I/O library fflush function ....
Later followed the code, found that the results are very different ...
Let's start with the results:
1. The file system functions in PHP (fopen, fwrite, fread, fseek, etc.) are used internally by system calls such as open, write, read, Seek, and so on, without a standard I/O library.
2. The Fflush function does not have any effect when applied to ordinary files.
Tracking process:
From the ext/standard/file.c.
Php_named_function (Php_if_fopen)
As a portal, we finally found the following definition in MAIN/STREAMS/PLAIN_WRAPPER.C
Phpapi Php_stream_ops php_stream_stdio_ops = {
Php_stdiop_write, Php_stdiop_read,
Php_stdiop_close, Php_stdiop_flush,
"STDIO",
Php_stdiop_seek,
Php_stdiop_cast,
Php_stdiop_stat,
Php_stdiop_set_option
};
This is the underlying implementation of the main file system functions applied on ordinary files
Take Php_stdiop_flush (fflush for PHP User Configuration) as an example:
static int Php_stdiop_flush (Php_stream *stream tsrmls_dc)
{
Php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
ASSERT (data! = NULL);
/*
* Stdio buffers data in the user land. by calling Fflush (3), this
* Data is send to the kernel using write (2). Fsync ' ing is
* Something completely different.
*/
if (data->file) {
Return Fflush (Data->file);
}
return 0;
}
While the ordinary files in the initialization process (can be seen during the process of tracking open), is not set data->file this field, but the use of data->fd ....
So fflush is not called here, that is, when fflush is used in ordinary files, it has no effect.
AUTHOR:SELFIMPR mail:lgg860911@yahoo.com.cn
http://www.bkjia.com/PHPjc/478561.html www.bkjia.com true http://www.bkjia.com/PHPjc/478561.html techarticle today and colleagues to discuss the role of the Fflush function, the PHP file system function should be built on the system's standard I/O library, so, arbitrarily think the role of fflush is to brush out the standard ...