我在 Laravel 中有一份工作,使用 Laravel 文件系统将 .zip 文件从 ftp 服务器下载到本地磁盘。这些文件的大小从几 MB 到几 GB 不等。
这是我当前的代码,只要我增加max_execution_time:
public function handle()
{
ini_set('max_execution_time', 300);
$destination = storage_path('app/temp/' . $this->import->unique_filename);
$ftpDisk = Storage::disk($this->import->disk);
$stream = $ftpDisk
->getDriver()
->readStream($this->import->filename);
file_put_contents($destination, stream_get_contents($stream), FILE_APPEND);
}
是否有可能将下载的文件分成更小的块?或者另一个比将 max_execution_time 设置为最大值更好的选项?
另一种方法是在 ftp 服务器上提取存档并逐个文件读取内容(csv/json 和图像)。
凤凰求蛊