[wp-trac] [WordPress Trac] #16925: Move the WP_Filesystem_SSH2 class to a plugin
WordPress Trac
wp-trac at lists.automattic.com
Tue Jul 5 05:12:27 UTC 2011
#16925: Move the WP_Filesystem_SSH2 class to a plugin
--------------------------+-----------------------------
Reporter: dd32 | Owner: dd32
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: Future Release
Component: Filesystem | Version:
Severity: normal | Resolution:
Keywords: needs-patch |
--------------------------+-----------------------------
Comment (by knuthmorris):
Oh - and let's try phpseclib without either gmp or bcmath. Doing so will
require a slight modification to urdd's script:
{{{
<?php
include('Net/SFTP.php');
define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
$sftp = new Net_SFTP('www.domain.tld', 22);
$sftp->login('user', 'pass');
$start = microtime(true);
$sftp->put('test', str_repeat('a', 256 * 1024));
$elapsed = microtime(true) - $start;
echo "took $elapsed seconds\r\n";
$connection = ssh2_connect('www.domain.tld', 22);
ssh2_auth_password($connection, 'user', 'pass');
$sftp = ssh2_sftp($connection);
$start = microtime(true);
$stream = fopen("ssh2.sftp://$sftp/home/user/test", 'w');
fputs($stream, str_repeat('a', 256 * 1024));
fclose($stream);
$elapsed = microtime(true) - $start;
echo "took $elapsed seconds\r\n";
?>
}}}
See the define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL)?
That's new. And here's what we get with that:
{{{
Trial #1:
took 6.8606338500977 seconds
took 7.5764989852905 seconds
Trial #2:
took 5.2222318649292 seconds
took 7.167053937912 seconds
Trial #3:
took 5.325345993042 seconds
took 7.7823340892792 seconds
}}}
Oh snap. phpseclib owns again.
Let's try it without mcrypt or gmp or bcmath. I ensure that mcrypt is not
used by doing define('CRYPT_RC4_MODE', CRYPT_RC4_MODE_INTERNAL). Pure-PHP
for everything.
{{{
Trial #1:
took 5.2221701145172 seconds
took 7.4742610454559 seconds
Trial #2:
took 5.2241580486298 seconds
took 7.8221480846405 seconds
Trial #3:
took 5.2212400436401 seconds
took 7.8840770721436 seconds
}}}
phpseclib wins again.
But just in case you believe I'm cooking the books and you're too lazy to
verify the results for yourself, here's proof that the bottleneck is how
the network packets are handled.
{{{
<?php
include('Crypt/RC4.php');
include('Crypt/Random.php');
define('CRYPT_RC4_MODE', CRYPT_RC4_MODE_INTERNAL);
$rc4 = new Crypt_RC4();
$key = '';
for ($i = 0; $i < 16; $i++) {
$key.= pack('n', crypt_random(0, 0xFFFF));
}
$rc4->setKey($key);
$start = microtime(true);
$rc4->encrypt(str_repeat("\0", 1536));
$rc4->encrypt(str_repeat('a', 1024 * 1024));
$elapsed = microtime(true) - $start;
echo "took $elapsed seconds\r\n";
}}}
phpseclib uses arcfour256 by default hence my using Crypt_RC4 as well.
str_repeat("\0", 1536) is encrypted because that's apparently what
arcfour256 requires, per the source code comments in phpseclib. Also,
note how we're encrypting 1MB instead of the 256KB that we're uploading
via SFTP. And here are the times using phpseclib's pure-PHP RC4
implementation:
{{{
Trial #1:
took 2.6884229183197 seconds
Trial #2:
took 2.76646900177 seconds
Trial #3:
took 2.8742060661316 seconds
}}}
So, basically, it takes less time to encrypt 1MB then it takes to upload
256KB. The bottleneck in SFTP isn't solved by simply using C instead of
PHP and phpseclib IS faster.
Don't believe me? Try it for yourself. I'm not included the source code
to make my post bigger. I'm including it so you can verify my results
instead of pulling random - and false - factoids out of thin air.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16925#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list