通过Samba对文件系统中的文件进行file_get_contents操作的超时。

问题描述 投票:1回答:1

我在尝试使用file_get_contents时遇到了一个错误,如

$filepath = "sharedFolder/image.gif";
$contents = file_get_contents($filepath);

当使用试图抓取通过Samba共享的文件系统中的文件时,出现了一个问题:由于VPN连接的问题,file_get_contents无法找到共享文件,在试图找到文件时,整个脚本被挂起。 由于VPN连接的问题,file_get_contents无法找到共享的文件,在它试图找到文件的时候,它挂掉了整个脚本。有没有办法给file_get_contents增加一个超时时间,这个超时时间大致相当于

$ctx = stream_context_create(array('http'=>
        array(
            'timeout' => 15,  //15 Seconds 
        )
    ));
$filepath = "sharedFolder/image.gif";
$contents = file_get_contents($filepath, false, $ctx);

但对于Samba共享的文件系统中的文件,而不是http?

php file-get-contents samba
1个回答
0
投票

建议1:当你在使用试图抓取文件系统中的文件时,你会发现文件系统中的文件都是..:

if (file_exists($filepath)) {
    $contents = file_get_contents($filepath);
} else {
    echo "Oupss VPN Error";
}

建议2:在你的varwww中做一个符号链接。

在你的varwwwhtml中建立一个samba挂载的符号链接......并使用你的代码stream_context_create......。(只允许localhost访问你在varwwwhtml中的新目录)

© www.soinside.com 2019 - 2024. All rights reserved.