如何知道sftp文件传输速度和所用时间


how to know sftp file transfer speed and time taken

有没有一种方法可以计算所花费的时间&通过php中的sftp下载/上传文件的速度与以下类似?

$sftp->get('filename', 'local/filename'); //gets the file
$sftp->size('filename'); //gives the size of the file.

这两个命令获取文件&给出了大小。。这样我们就可以计算出速度&花费的时间?

当然可以,您拥有所需的所有数据:时间和大小。

$start = time();
$sftp->get('filename', 'local/filename'); //gets the file
$size = $sftp->size('filename'); //gives the size of the file.
$timeTakenInSeconds = time() - $start;
echo sprintf('Bytes/second: %d', $size / $timeTakenInSeconds);