Gaufrette icon indicating copy to clipboard operation
Gaufrette copied to clipboard

Adapter/Ftp Large File Read / Write

Open anvaya opened this issue 8 years ago • 3 comments

The Ftp Adapter methods are not ideal for large file read and write.

Write Method => Has parameter $content, for a large file this means saving entire file contents in a variable and then send to this method. Does not seem to support either file path or open handle.

Read Method => Again downloads the entire file to the server from remote FTP server, and then reads the contents into a variable. This is problematic for large files which are essentially need to be streamed to the client browser.

Suggestions:

  1. Please add WriteFile method with $path parameter or $handle parameter to write from existing file.
  2. For Read, consider adding support for stream output so that it can then be forwarded to client browser without saving on the web server.

If the functionality already exists, please let us know.

anvaya avatar May 30 '16 14:05 anvaya

This is not specific to the FTP adapter btw. This is a limitation due to the Adapter interface used in Gaufrette. And this cannot change without a major overhaul of the whole library.

stof avatar May 30 '16 14:05 stof

@anvaya if your needs are only about FTP rather than about using the Gaufrette API, you could use ftp_fget calls directly to perform reads, as it reads to a PHP stream (and ftp_fput also reads from a stream)

stof avatar May 30 '16 14:05 stof

Well, we are actually using it in a scenario where the document root can be a Local, FTP and probably going forward other sources like S3. Hence found this library extremely interesting.

We found some code that was very interesting:

http://stackoverflow.com/questions/1397182/stream-ftp-download-to-output

An implementation seems to be working well (although we are still testing it.) Only difference being we used STREAM_PF_INET in stream_socket_pair function call.

On Mon, May 30, 2016 at 8:16 PM, Christophe Coevoet < [email protected]> wrote:

@anvaya https://github.com/anvaya if your needs are only about FTP rather than about using the Gaufrette API, you could use ftp_fget calls directly to perform reads, as it reads to a PHP stream (and ftp_fput also reads from a stream)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/KnpLabs/Gaufrette/issues/416#issuecomment-222507544, or mute the thread https://github.com/notifications/unsubscribe/ACyvJz2szCkfOqeVBMa9sTMW9pt7hmImks5qGvhGgaJpZM4Ip1JW .

anvaya avatar May 30 '16 15:05 anvaya