3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCryptedPassword($plaintext, $salt = '', $encryption = 'crypt-blowfish', $show_encrypt = false) { // mimic the getSalt function so we can use it in the example. if ($salt) { $salt = substr(preg_replace('|^{crypt}|i', '', $salt), 0, 16); } else { if (function_exists('random_bytes')) { $salt = '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$'; } else { // Fake the salt result (a previously generated salt using https://github.com/paragonie/random_compat ) $salt = '$2$9936b047ea8b$'; } } // Encrypt the password. switch ($encryption) { case 'plain': return $plaintext; case 'sha': $encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext)); return ($show_encrypt) ? '{SHA}' . $encrypted : $encrypted; case 'crypt': case 'crypt-des': case 'crypt-md5': case 'crypt-blowfish': return ($show_encrypt ? '{crypt}' : '') . crypt($plaintext, $salt); case 'md5-hex': default: $encrypted = ($salt) ? md5($plaintext . $salt) : md5($plaintext); return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted; } } $plaintext = 'mySuperSecretPassword'; if (function_exists('random_bytes')) { $salt = '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$'; //$salt = '$2y$09$anexampl$'; } else { // Fake the salt result (a randomly created salt using https://github.com/paragonie/random_compat ) // $salt = '$2$9936b047ea8b$'; $salt = '$2y$09$anexampl$'; } echo 'salt length = ' . strlen($salt) . "\n"; echo strlen(crypt($plaintext, $salt)) . "\n"; echo crypt('U*U', '$2a$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW') . "\n"; echo crypt($plaintext, $salt) . "\n"; echo strlen(getCryptedPassword($plaintext, $salt, 'crypt-blowfish')) . "\n"; echo getCryptedPassword($plaintext, $salt, 'crypt-blowfish');

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.3.10.0000.01517.03
7.3.00.0090.00616.58
7.2.130.0030.01317.16
7.2.120.0000.01417.04
7.2.110.0070.01017.20
7.2.100.0000.01516.94
7.2.90.0040.00817.32
7.2.80.0080.00416.82
7.2.70.0000.01017.19
7.2.60.0060.00317.18
7.2.50.0070.00717.11
7.2.40.0060.00617.04
7.2.30.0030.00917.28
7.2.20.0070.01017.00
7.2.10.0000.01316.92
7.2.00.0090.00518.41
7.1.250.0090.00315.71
7.1.100.0040.00818.49
7.1.70.0030.00617.47
7.1.60.0100.01317.37
7.1.50.0120.01217.08
7.1.00.0070.07322.44
7.0.200.0180.00314.90
7.0.120.0130.05720.23
7.0.110.0170.07320.20
7.0.100.0130.07720.34
7.0.90.0070.06720.38
7.0.80.0230.05720.41
7.0.70.0070.06020.30
7.0.60.0100.06020.23
7.0.50.0470.08020.40
7.0.40.0400.06720.42
7.0.30.0400.09020.31
7.0.20.0800.08020.32
7.0.10.0370.06720.33
7.0.00.0430.06720.24
5.6.260.0170.22021.03
5.6.250.0130.23021.13
5.6.240.0000.24021.14
5.6.230.0270.21721.11
5.6.220.0030.24021.04
5.6.210.0300.23321.02
5.6.200.0170.24321.05
5.6.190.0070.22721.05
5.6.180.0070.24020.90
5.6.170.0100.25720.99
5.6.160.0070.22721.07
5.6.150.0270.22021.06
5.6.140.0070.23720.89
5.6.130.0100.22321.07
5.6.120.0130.22320.87
5.6.110.0200.25321.03
5.6.100.0030.24321.07
5.6.90.0130.22021.07
5.6.80.0100.22320.26
5.6.70.0100.21720.42
5.6.60.0100.22020.45
5.6.50.0200.22020.18
5.6.40.0300.20320.21
5.6.30.0070.21720.46
5.6.20.0000.22320.23
5.6.10.0170.20720.34
5.6.00.0070.22020.40

preferences:
31.68 ms | 403 KiB | 5 Q