fseek($fd,0);
改成rewind($fd)试试

解决方案 »

  1.   

    你说到重新关闭提醒了我
    在对文件进行写入的时候,不防把文件先用flock锁住。
    这样可能会好一些的。
      

  2.   

    To phpteam:
    这两个命令不都是把指针移动到文件首吗?
    To mostice:
    为什么先要锁住?
      

  3.   

    我在写ASP时也是这样,这样确实是有点麻烦.
    关注这个问题.
      

  4.   

    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函数, 强制刷新缓冲区, 写入文件, 试试.
      

  5.   

    我使用fflush()试过了,不好用。将第一次出现的 $fd=fopen($counterfile,"r+")
    改成
    $fd = @fopen($counterfile, "r+");否则,文件不存在会出错。在我的机器上,第一次运行就出现了这个错误。