unlink("cache/data.xml");
我觉得,当服务器可能正在阅读并将其提供给访问者时,这可能会产生错误.
如何安全地删除文件,以便脚本将继续等待,直到从Web服务器读取锁定被释放,然后继续删除该文件或如何在那里工作?
谢谢
解决方法:
这将取决于运行的特定系统,但UNIX unlink函数的手册页(PHP unlink函数很可能依赖于内部)说明:
The
unlink()
function removes the link named by path from its
directory and decrements the link count of the file which was
referenced by the link. If that decrement reduces the link count of
the file to zero, and no process has the file open, then all
resources associated with the file are reclaimed. If one or more
process have the file open when the last link is removed, the link is
removed, but the removal of the file is delayed until all references
to it have been closed.
换句话说,即使在删除文件时,读取文件的过程也可以继续这样做.