-1

Is there a way to calculate the time taken & the speed for downloading/uploading a file via sftp in php as similar to the below?

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

These two commands fetches the file & gives the size..in that way can we calculate the speed & time taken?

neubert
  • 15,947
  • 24
  • 120
  • 212
kumar
  • 1,796
  • 2
  • 15
  • 37
  • The question should be asked after at least minimal effort has been made to do something yourself. – Eugene Mayevski 'Callback Dec 09 '15 at 20:24
  • phpseclib's complex logs show how long each packet took to send receive. I suppose you could manually add each of those values up.. – neubert Dec 10 '15 at 16:52
  • @EugeneMayevski'EldoSCorp Thank you very much, we can create in any number of ways as we like but following/trying to know some existing functions is not a bad practice. This is what I've asked there..that do we have some way through sftp? – kumar Dec 15 '15 at 09:51

1 Answers1

0

Of course you can, you have all the data you need: time and size.

$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);
Aykut Çevik
  • 2,060
  • 3
  • 20
  • 27