Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确认何时使用PHP';s`file\u put\u contents()`已完成_Php_Laravel_Laravel 5 - Fatal编程技术网

确认何时使用PHP';s`file\u put\u contents()`已完成

确认何时使用PHP';s`file\u put\u contents()`已完成,php,laravel,laravel-5,Php,Laravel,Laravel 5,在我的Laravel应用程序中,我使用流媒体将大文件(>1GB)下载到我的服务器上进行额外处理: $stream = Storage::disk('google')->getDriver()->readStream($file['path']); file_put_contents(public_path("files/{$filename}.tiff"), stream_get_contents($stream)); if (file_exists(pub

在我的Laravel应用程序中,我使用流媒体将大文件(>1GB)下载到我的服务器上进行额外处理:

    $stream = Storage::disk('google')->getDriver()->readStream($file['path']);
    file_put_contents(public_path("files/{$filename}.tiff"), stream_get_contents($stream));

    if (file_exists(public_path("files/{$filename}.tiff"))) {
        ConvertTIFF::dispatch();
        return;
    }
问题是,因为我正在对文件进行流式处理,文件本身在流式处理实际完成之前很久就被创建了。因此,我的
文件\u exists()
check会在文件完成之前频繁触发我的
ConvertTIFF
事件

是否有更简单的方法来检查
文件\u put\u contents()
流式处理是否完成?或者是否有方法使进程阻塞,从而在文件完全下载之前不会触发事件?

file\u put\u contents()
返回写入文件的字节数,如果不成功,则返回False。所以你可以像这样检查状态

$status = file_put_contents(public_path("files/{$filename}.tiff"), stream_get_contents($stream));

/*if ($status) {
    echo "success";
} else {
    echo "failed";
}*/

return $status;
file\u put\u contents()
返回写入文件的字节数,如果不成功,则返回False。所以你可以像这样检查状态

$status = file_put_contents(public_path("files/{$filename}.tiff"), stream_get_contents($stream));

/*if ($status) {
    echo "success";
} else {
    echo "failed";
}*/

return $status;

老实说,你可能想考虑一个基于工作者的方法,你可能想考虑一个基于工作者的方法,老实说。