检查 PHP 中的 NFS 共享是否已启动
我正在开发一个可以存储上传文件的系统。元数据将进入本地可访问的数据库,但文件本身将通过 NFS 存储在远程设备上,以便 PHP 可以与服务器交互,就像它是一个目录一样。
我发现如果有人在 NFS 服务器关闭或不可用时尝试上传文件,可能会出现一个问题,这可能会导致脚本出错或挂起。显然,我们希望避免这种情况并以优雅的方式处理它,但我们不确定如何才能做到这一点。
我们正在考虑 a) 在页面显示时检查服务器,并在服务器关闭时隐藏表单的文件上传部分,或者 b) 在执行 move_uploaded_file 之前检查链接以存储上传的文档。
是否可以从 PHP 内部执行此操作?如果可以,如何执行?
I am working on a system that will store uploaded files. The metadata will go into a locally-accessible database, but the files themselves are going to be stored on a remote box via NFS so that PHP can interact with the server as if it was a directory.
I identified an issue that may occur if somebody attempts to upload a file when the NFS server is down or otherwise unavailable, which could cause the script to error out or hang. Obviously we want to avoid this scenario and handle it in a graceful manner, but we aren't sure how we can do this.
We are thinking of a) checking the server at page-display time and ghosting out the file upload portion of the form should the server be down, or b) checking the link before executing move_uploaded_file to store the uploaded document.
Is it possible to do this from within PHP, and if so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 http://www.php.net/manual/en/ function.stream-set-timeout.php
您可以编写一个简单的检查,尝试以 2 秒超时写入 NFS 共享。如果成功,则继续 move_uploaded_file。如果失败,则给用户一个优雅的错误。
Checkout http://www.php.net/manual/en/function.stream-set-timeout.php
You could write a simple check that tries to write to the NFS share with a 2 second timeout. If it succeeds, proceed with the move_uploaded_file. If it fails, give the user a graceful error.
我不知道你的设置是什么样的...如果你正在安装它,你可以使用
is_writable
吗?I don't know what your setup looks like... If you are mounting it, could you use
is_writable
?我会尝试在 nfs-mountpoint 上真正编写一个小文件,如果成功,您就在线并且可以编写发布的文件。
如果没有,请将其缓存在网络服务器磁盘上以供以后(自动)保存。
I'd try to write a small file for real at nfs-mountpoint, if success you're online and can write the posted file.
If not, cache it at webserver-disk for later (automatic) save.
检查是否可以 opendir() 目录?
Check if you can opendir() the directory?