dongtan5555 2012-04-16 09:43
浏览 14
已采纳

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

unlink("cache/data.xml");

I feel that this may generate an error at times when sever might be reading and serving it to the visitor.

how to safely delete the file so script will continue to wait until the read lock from the web server is released if any and then continue deleting the file or how it works out there?

Thanks

  • 写回答

1条回答 默认 最新

  • drcomwc134525 2012-04-16 09:54
    关注

    This will depend on the specific system this is running on, but the man page for the UNIX unlink function (which the PHP unlink function very likely relies on internally) says this:

    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.

    In other words, the process reading the file can continue to do so, even while the file is being deleted.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题