gpt4 book ai didi

php - 如果在 Web 服务器正在向网站访问者提供文件时删除 PHP 中的文件,会发生什么情况

转载 作者:可可西里 更新时间:2023-11-01 00:49:43 24 4
gpt4 key购买 nike

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.

换句话说,读取文件的进程可以继续这样做,即使文件正在被删除。

关于php - 如果在 Web 服务器正在向网站访问者提供文件时删除 PHP 中的文件,会发生什么情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10171829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com