检查PHP中是否有NFS共享 [英] Check if NFS share is up in PHP
问题描述
如果有人尝试在NFS服务器关闭或不可用时上传文件,可能会导致脚本出错或挂起,可能会出现此问题。显然,我们想避免这种情况,并以优雅的方式处理它,但是我们不知道我们如何做到这一点。
我们正在考虑:a)在页面显示时检查服务器,并在服务器关闭时重新启动表单的文件上传部分,或b)检查执行move_uploaded_file以存储上传的文档之前的链接。
是否可以在PHP中执行此操作,如果是这样,怎么办?
结帐 http://www.php.net/manual/en/function.stream-set-timeout.php
您可以编写一个简单的检查,尝试以超过2秒的时间写入NFS共享。如果成功,请继续执行move_uploaded_file。如果失败,给用户一个优雅的错误。
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?
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.
这篇关于检查PHP中是否有NFS共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!