3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * per https://stackoverflow.com/a/31107425 */ function get_random_string($length = 16, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } // Tests. echo 'Test 01: ' . get_random_string() . "\n"; echo get_random_string(2) . "\n"; echo get_random_string(32) . "\n"; echo get_random_string(16, '1234567') . "\n"; echo get_random_string(16, '123abcABC') . "\n"; echo get_random_string(16, 'ABC') . "\n"; echo get_random_string(16, '10') . "\n";

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.2.90.0030.01714.90
7.2.80.7470.01014.62
7.2.70.5400.01014.80
7.2.60.4760.00714.93
7.2.50.5130.00314.79
7.2.40.4070.00714.98
7.2.30.4610.00315.14
7.2.20.3950.01314.95
7.2.10.3640.01314.98
7.2.00.4160.01014.87
7.1.210.0780.01013.94
7.1.200.0180.00914.07
7.1.190.4570.01013.79
7.1.180.4380.01914.03
7.1.170.4090.00313.80
7.1.160.4940.01313.86
7.1.150.4210.01213.94
7.1.140.3670.01313.80
7.1.130.4030.00713.80
7.1.120.4470.00714.03
7.1.110.3960.01013.89
7.1.100.3940.00313.88
7.1.90.5600.00314.09
7.1.80.4390.01314.00
7.1.70.5290.01014.00
7.1.60.5270.01331.96
7.1.50.6390.01631.77
7.1.40.7920.00631.76
7.1.30.6880.01331.80
7.1.20.6340.01632.00
7.1.10.6900.01313.88
7.1.00.5200.01313.75

preferences:
27.08 ms | 401 KiB | 5 Q