请教PHP fflush 的问题, not working

WBOY
Release: 2016-06-06 20:21:44
Original
1349 people have browsed it

有没有用过fflush函数

官方解释是这样说的:
Flushes the output to a file
This function forces a write of all buffered output to the resource pointed to by the file handle.

也就是说把文件的写入缓存强行释放输出到文件指针.
http://php.net/manual/en/function.fflush.php

但我发现 fwrite 在执行完之后, 内容就马上写入文件了. 不需要fflush, 也不需要fclose, 对这个问题感到很疑惑, fflush 究竟有提供了什么作用.

代码:

Copy after login
Copy after login

回复内容:

有没有用过fflush函数

官方解释是这样说的:
Flushes the output to a file
This function forces a write of all buffered output to the resource pointed to by the file handle.

也就是说把文件的写入缓存强行释放输出到文件指针.
http://php.net/manual/en/function.fflush.php

但我发现 fwrite 在执行完之后, 内容就马上写入文件了. 不需要fflush, 也不需要fclose, 对这个问题感到很疑惑, fflush 究竟有提供了什么作用.

代码:

Copy after login
Copy after login

给你参考一个方法stream_set_write_buffer,默认的buffer_size8K,也就是说,fwrite如果一次写入的数据量大于buffer_size,会拆分写入。这种情况在多进程操作同一文件时需要考虑,通常情况下fflush是没多大作用的,不过加了也无所谓,毕竟fopen还能打开其他的文件似的资源。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!