[PHP kernel] Some situations----file system functions for normal files _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.