[Php kernel] ---- some situations when file system functions are used for common files _ PHP Tutorial

Source: Internet
Author: User
[Php kernel] ---- file system functions are used in common files. Today, I talked to my colleagues about the function of fflush. I thought that the file system function of php should be built on the standard IO Library of the system. therefore, the role of fflush is to refresh the standards. today, I talked to my colleagues about the function of fflush. I thought php's file system functions should be built on the standard I/O library of the system, therefore, the role of fflush is to fl the buffer of the standard I/O library, which is equivalent to the fflush function of the standard I/O library ....

Later I tracked the code and found that the results were quite different...

Let's talk about the result first:

1. when the file system functions (fopen, fwrite, fread, fseek, etc.) in php are applied to common files, they use open, write, read, seek and other internal system calls for processing, without passing through the standard I/O library.

2. the fflush function does not apply to common files.

Tracking process:

From ext/standard/file. c

PHP_NAMED_FUNCTION (php_if_fopen)

As the entry, find 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 to common files.

Take php_stdiop_flush (corresponding to the php user state fflush) 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 user land. By calling fflush (3), this

* Data is sent to the kernel using write (2). fsync 'ing is

* Something completely different.

*/

If (data-> file ){

Return fflush (data-> file );

}

Return 0;

}

While a common file is not set with the data-> file field during initialization (which can be seen during tracking the open process), data-> fd ....

Therefore, fflush will not be called. that is to say, fflush has no effect when it is used in common files.

Author: selfimip mail: lgg860911@yahoo.com.cn

Finally, I thought that php's file system functions should be built on the standard I/O library of the system. Therefore, I think fflush is used to flush 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.