简体   繁体   English

加速op phpseclib sftp的方法可以下载远程文件

[英]Ways to speed op phpseclib sftp get to download remote file

So I use phpseclib which downloads a 50MB file over sftp in roughly 45 seconds. 所以我使用phpseclib,它在大约45秒内通过sftp下载50MB文件。 Which is fast compared to ssh2_scp_recv() which takes 90+ seconds, but slow compared to my sftp client (filezilla), which takes 10 seconds max. 与ssh2_scp_recv()相比,这个速度要快90秒,但与我的sftp客户端(filezilla)相比速度较慢,最长需要10秒。

My question is, what can I do to speed up file downloads through sftp, other than enabling the mcrypt, gmp and bcmath extensions which I've done already? 我的问题是,除了启用我已经完成的mcrypt,gmp和bcmath扩展之外,我还能做些什么来加速通过sftp下载文件?

I'm running PHP 5.5 on Windows 7, and got the same results when using either cli or browser/apache, and using sftp->get to download a file as a whole, or download a file in chunks of various sizes. 我在Windows 7上运行PHP 5.5,并且在使用cli或者浏览器/ apache时使用sftp-> get来整体下载文件,或者以各种大小的块下载文件时得到相同的结果。

Source: 资源:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
require 'phpseclib/Net/SFTP.php';

$sftp = new Net_SFTP($host, $port, $timeout);
$sftp->login($user, $password);

$sftp->get($remoteFile, $localFile);

With an SFTP protocol, a client (client library) uses a "READ" request repeatedly to get chunks of file contents. 使用SFTP协议,客户端(客户端库)反复使用“READ”请求来获取文件内容块。

A dumb implementation, that phpseclib uses, sends one "READ" request (for up to 32 kB), waits for a "DATA" response, sends another "READ" request, waits, and so on, until it gets a whole file. phpseclib使用的一个哑实现发送一个“READ”请求(最多32 kB),等待“DATA”响应,发送另一个“READ”请求,等待,等等,直到它获得整个文件。

If a roundtrip to/from a server is long (big latency), the client (library) may be uselessly waiting most of the time. 如果往返服务器的往返很长(大延迟),则客户端(库)可能在大多数情况下无用地等待。

Smart clients (libraries) overcome this by sending multiple "READ" requests, without waiting for the response, or by using a large "READ" request, or both. 智能客户端(库)通过发送多个“READ”请求,无需等待响应,或使用大的“READ”请求或两者来克服此问题。

FileZilla for instance, sends a sequence of 32 kB "READ" requests for up to total 1 MB worth of data. 例如,FileZilla发送一系列32 kB“READ”请求,最多可获得1 MB的数据。

The phpseclib does not support this optimization (note, that it does for uploads, though). phpseclib不支持这种优化(注意,它适用于上传)。

All you can do is to increase a size of the "READ" request, using Net_SFTP::max_sftp_packet . 您所能做的就是使用Net_SFTP::max_sftp_packet增加“READ”请求的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM