To phpteam: 这两个命令不都是把指针移动到文件首吗? To mostice: 为什么先要锁住?
我在写ASP时也是这样,这样确实是有点麻烦. 关注这个问题.
fflush (PHP 4 >= 4.0.1)fflush -- Flushes the output to a file Description int fflush ( int fp)This function forces a write of all buffered output to the resource pointed to by the file handle fp. Returns TRUE if successful, FALSE otherwise. The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen(). --------------------------- 用fflush函数, 强制刷新缓冲区, 写入文件, 试试.
在对文件进行写入的时候,不防把文件先用flock锁住。
这样可能会好一些的。
这两个命令不都是把指针移动到文件首吗?
To mostice:
为什么先要锁住?
关注这个问题.
(PHP 4 >= 4.0.1)fflush -- Flushes the output to a file
Description
int fflush ( int fp)This function forces a write of all buffered output to the resource pointed to by the file handle fp. Returns TRUE if successful, FALSE otherwise. The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen(). ---------------------------
用fflush函数, 强制刷新缓冲区, 写入文件, 试试.
改成
$fd = @fopen($counterfile, "r+");否则,文件不存在会出错。在我的机器上,第一次运行就出现了这个错误。