检查 PHP 中的 NFS 共享是否已启动

发布于 2024-10-01 19:12:02 字数 326 浏览 4 评论 0原文

我正在开发一个可以存储上传文件的系统。元数据将进入本地可访问的数据库,但文件本身将通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

熊抱啵儿 2024-10-08 19:12:02

查看 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.

她如夕阳 2024-10-08 19:12:02

我不知道你的设置是什么样的...如果你正在安装它,你可以使用 is_writable 吗?

if (!is_writable('/path/to/nfs/share/mount')) {
   die('NFS share is not writable!');
}

I don't know what your setup looks like... If you are mounting it, could you use is_writable?

if (!is_writable('/path/to/nfs/share/mount')) {
   die('NFS share is not writable!');
}
夏至、离别 2024-10-08 19:12:02

我会尝试在 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.

森罗 2024-10-08 19:12:02

检查是否可以 opendir() 目录?

<?php
$dir = "/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        // do your stuff
        closedir($dh);
    }
}
?>

Check if you can opendir() the directory?

<?php
$dir = "/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        // do your stuff
        closedir($dh);
    }
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文