检查PHP中是否有NFS共享 [英] Check if NFS share is up in PHP

查看:164
本文介绍了检查PHP中是否有NFS共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个将存储上传文件的系统。元数据将进入本地可访问的数据库,但是文件本身将通过NFS存储在远程框上,以便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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆