2

In my project, I use sftp (https://www.php.net/manual/en/book.ssh2.php) to upload file to remote server.

Code upload file:

    if (!$localStream = @fopen($localFilePath, 'r')) {
        throw new Exception("Unable to open local file for reading: $localFilePath");
    }

    // Remote stream
    if (!$remoteStream = @fopen("ssh2.sftp://".$sftp_int."/$savePath", 'w')) {
        throw new Exception("Unable to open remote file for writing: $savePath");
    }

    // Write from our remote stream to our local stream
    $read = 0;
    $fileSize = filesize($localFilePath);
    while ($read < $fileSize && ($buffer = fread($localStream, $fileSize - $read))) {
        // Increase our bytes read
        $read += strlen($buffer);

        // Write to our local file
        if (fwrite($remoteStream, $buffer) === false) {
            throw new Exception("Unable to write to local file: $savePath");
        }
    }

But I tracking & see speed upload slow.

I research and found: Why is SSH2 SFTP so much slower than FTP and FTPS?

And: http://phpseclib.sourceforge.net/

How to increase upload speed using sftp with PHP?

Please, help me. Thanks

Alex
  • 3,646
  • 1
  • 28
  • 25
  • @MartinPrikryl yes, but I dont see speed better :( – Alex Sep 27 '19 at 09:32
  • @MartinPrikryl: I want to try use psftp. Do can it better libssh2? Thank you. – Alex Sep 27 '19 at 09:34
  • 2
    For phpseclib I'd say post logs of you uploading a _small_ file so that the bottleneck can possibly be identified. You can get them by doing `define('NET_SSH2_LOGGING', 2);` at the top and then `echo $sftp->getSFTPLogs();` after the upload. Two other things: (1) how long is it taking you to upload your intended file? I ask because "slow" can be subjective. Also, post your `phpinfo()`. Certain combinations of extensions may speed things up for you. – neubert Sep 27 '19 at 12:22

0 Answers0