【问题标题】:Timeout for file_get_contents for file in filesystem over SambaSamba 文件系统中文件的 file_get_contents 超时
【发布时间】:2020-06-11 15:40:24
【问题描述】:

我在尝试使用 file_get_contents 时遇到错误

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

当试图在通过 Samba 共享的文件系统中抓取文件时。由于 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】:

    建议一:

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

    建议二:

    在您的 /var/www/html/ 中创建一个符号链接到您的 samba 挂载 ... 并将您的代码与 stream_context_create .... 一起使用。(仅允许 localhost 访问 /var/www/html 中的新目录)

    【讨论】:

      猜你喜欢
      • 2012-01-11
      • 2017-12-16
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 2018-04-10
      • 2012-09-01
      • 2010-10-05
      • 2013-02-02
      相关资源
      最近更新 更多