Laravel flysystem sftp upload slow

923 Views Asked by At

I need make upload to a remote server. I made a new disk in filesystems.php

And my upload code looks like this:

$path = 'storage1';
$fileName = Str::random().'.'. $request->file->getClientOriginalExtension();
Storage::disk('sftp')->putFileAs($path, $request->file, $fileName);

However, the upload takes a long time. On the frontend i have an upload progress bar which gets stuck 100% (upload via AJAX).

  1. I will select a file - the progress bar will start
  2. Only when it is 100% does the file actually start writing to the remote disk
  3. Only when the file is uploaded to the remote server and then I get an ajax response from the server

Is the file uploaded to some php /tmp/ first and then when it is uploaded will it start uploading to the remote server? Is it possible to bypass it so that it goes directly there? Or do upload to a remote server via a background job, first upload to webstorage and then move to remote server on background?

My next question is how to do "disk loadbalancing"? For example, I have 3 disks mounted on server. How I check disk /storage1/ how much free space does it have? If it has more than 80% of total capacity then choose to upload to /storage2/

0

There are 0 best solutions below