3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * SMS Signin Gateway - HMAC class * @author adrian7 (adrian@studentmoneysaver.co.uk) * @version 1.1 */ /** * Generates/Validates HMAC signatures * Class HMAC * @link http://signin.studentmoneysaver.co.uk/docs/#API * @package App\Library */ class HMAC{ /** * Timezone */ const TZ = 'UTC'; /** * Cypher/algorithm to use * @see hash_algos() */ const CYPHER = 'sha256'; /** * Time frame in seconds, in which a message is considered valid */ const TIMEFRAME = 300; /** * Internal time format */ const TIME_FORMAT = 'Y-m-d H:i:s'; /** * Verifies a HMAC signature * @param $data * @param $signature * @param $privateKey * @param $timestamp * * @return bool */ public static function verify($data, $signature, $privateKey, $timestamp){ $now = self::timestamp(self::TZ); $tmin = ( $now - ( self::TIMEFRAME/2 ) ); $tmax = ( $now + ( self::TIMEFRAME/2 ) ); if( ( $timestamp < $tmin ) or ( $timestamp > $tmax ) ) return false; //out of time range $data = strval( $data ); $computed_sig = self::signature($data, $privateKey, $timestamp); return $signature == $computed_sig; } /** * Generates a HMAC signature * @param $data * @param $privateKey * @param null $timestamp * * @return string */ public static function signature($data, $privateKey, $timestamp=null){ $timestamp = empty($timestamp) ? self::timestamp(self::TZ) : intval($timestamp); $data = strval( $data ); $sig = base64_encode( hash_hmac(self::CYPHER, $data, $privateKey . '::' . date(self::TIME_FORMAT, $timestamp), true) ); echo "Time: " . $timestamp; return $sig; } /** * Generates timestamp based on timezone * @param string $tz * * @return int */ public static function timestamp($tz='UTC'){ $tz = new \DateTimeZone($tz); return date_create(NULL, $tz)->getTimestamp(); } /** * Validates a hash algorithm * @param $algo * @see hash_algos() * @return bool */ public static function isValidHashAlgo($algo){ $algos = hash_algos(); return in_array($algo, $algos); } } $timestamp = empty($timestamp) ? HMAC::timestamp(HMAC::TZ) : intval($timestamp); $url = "https://signin.studentmoneysaver.co.uk/api/?onSuccess=https%3A%2F%2Fwww.google.si%2Fsearch%3Fq%3Dsuccess&onFail=https%3A%2F%2Fwww.google.si%2Fsearch%3Fq%3Dfail&apikey=test-Yr82f2DowCdxRumRwAD8r66KMFF4GWDm&timestamp=$timestamp"; echo "Signature: " . HMAC::signature( $url, 'NP8T2NY2SR0XTNZ5', $timestamp);

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)
8.3.60.0110.01116.88
8.3.50.0270.01021.21
8.3.40.0070.00718.96
8.3.30.0070.00718.84
8.3.20.0040.00420.23
8.3.10.0000.00821.64
8.3.00.0030.01019.51
8.2.180.0110.00716.75
8.2.170.0000.01418.94
8.2.160.0040.01122.96
8.2.150.0070.00025.66
8.2.140.0040.01124.66
8.2.130.0070.00026.16
8.2.120.0060.00321.14
8.2.110.0060.00621.99
8.2.100.0040.00818.09
8.2.90.0060.00319.29
8.2.80.0050.00317.97
8.2.70.0000.00817.75
8.2.60.0040.00418.04
8.2.50.0030.00518.10
8.2.40.0000.00820.61
8.2.30.0070.00018.03
8.2.20.0040.00418.05
8.2.10.0110.00017.97
8.2.00.0000.00718.03
8.1.280.0070.01125.92
8.1.270.0080.00020.24
8.1.260.0070.00026.35
8.1.250.0080.00028.09
8.1.240.0040.00423.79
8.1.230.0000.01219.67
8.1.220.0060.00317.74
8.1.210.0030.00518.77
8.1.200.0060.00317.48
8.1.190.0000.00817.48
8.1.180.0050.00318.10
8.1.170.0070.00318.63
8.1.160.0060.00321.96
8.1.150.0000.00718.97
8.1.140.0000.00917.62
8.1.130.0060.00317.74
8.1.120.0070.00017.59
8.1.110.0050.00317.57
8.1.100.0030.00617.55
8.1.90.0040.00417.73
8.1.80.0050.00317.59
8.1.70.0000.00717.71
8.1.60.0030.00517.74
8.1.50.0030.00617.61
8.1.40.0000.00917.62
8.1.30.0000.00917.81
8.1.20.0040.00417.71
8.1.10.0000.00717.71
8.1.00.0040.00417.67
8.0.300.0000.00818.77
8.0.290.0060.00316.88
8.0.280.0040.00418.45
8.0.270.0000.00717.28
8.0.260.0000.00717.27
8.0.250.0000.00817.18
8.0.240.0030.00717.19
8.0.230.0000.00717.17
8.0.220.0030.00317.13
8.0.210.0000.00717.09
8.0.200.0030.00317.13
8.0.190.0000.00917.18
8.0.180.0000.00717.14
8.0.170.0080.00017.16
8.0.160.0030.00317.13
8.0.150.0000.00817.11
8.0.140.0040.00317.09
8.0.130.0000.00613.46
8.0.120.0030.00616.96
8.0.110.0040.00417.04
8.0.100.0040.00417.14
8.0.90.0070.00016.91
8.0.80.0080.00817.13
8.0.70.0040.00417.18
8.0.60.0030.00517.05
8.0.50.0000.00716.98
8.0.30.0060.01217.13
8.0.20.0120.00917.41
8.0.10.0050.00317.07
8.0.00.0130.00816.88
7.4.330.0050.00015.14
7.4.320.0030.00316.77
7.4.300.0060.00016.66
7.4.290.0000.00716.74
7.4.280.0040.00416.66
7.4.270.0000.00716.73
7.4.260.0030.00316.76
7.4.250.0080.00016.77
7.4.240.0020.00516.65
7.4.230.0070.00016.51
7.4.220.0060.01216.79
7.4.210.0040.01116.72
7.4.200.0000.00816.78
7.4.160.0070.01016.80
7.4.150.0140.00817.40
7.4.140.0090.01217.86
7.4.130.0100.00716.72
7.4.120.0090.00916.69
7.4.110.0170.00716.62
7.4.100.0140.00516.69
7.4.90.0070.01016.79
7.4.80.0070.01019.39
7.4.70.0150.00416.74
7.4.60.0030.01416.71
7.4.50.0080.00016.73
7.4.40.0090.00916.79
7.4.30.0120.00616.73
7.4.00.0060.00915.37
7.3.330.0000.00513.55
7.3.320.0030.00313.43
7.3.310.0050.00216.60
7.3.300.0030.00316.46
7.3.290.0070.00816.62
7.3.280.0090.01016.57
7.3.270.0160.00517.40
7.3.260.0170.00716.57
7.3.250.0100.01116.64
7.3.240.0100.00616.54
7.3.230.0100.01316.65
7.3.210.0130.00316.78
7.3.200.0070.01419.39
7.3.190.0120.00316.60
7.3.180.0110.00716.88
7.3.170.0060.01216.81
7.3.160.0070.01116.56
7.3.10.0150.00416.70
7.3.00.0060.00916.72
7.2.330.0090.01516.99
7.2.320.0000.01817.07
7.2.310.0150.00917.01
7.2.300.0080.01316.94
7.2.290.0030.02016.69
7.2.130.0090.00916.35
7.2.120.0090.00617.04
7.2.110.0120.01416.87
7.2.100.0080.00816.76
7.2.90.0030.01016.81
7.2.80.0130.01616.95
7.2.70.0110.01116.93
7.2.60.0160.01016.87
7.2.50.0240.00316.70
7.2.40.0130.00717.07
7.2.30.0150.01016.92
7.2.20.0180.00416.77
7.2.10.0190.00416.67
7.2.00.0090.00718.41
7.1.250.0180.00315.58
7.1.100.0610.00514.33
7.1.70.0110.00017.36
7.1.60.0110.01119.59
7.1.50.0110.00734.91
7.1.00.0070.07322.27
7.0.200.0040.00816.72
7.0.100.0470.09019.93
7.0.90.0400.07319.99
7.0.80.0330.06019.92
7.0.70.0430.08319.89
7.0.60.0470.07319.98
7.0.50.0430.08320.27
7.0.40.0100.07320.14
7.0.30.0070.09020.10
7.0.20.0070.08320.15
7.0.10.0130.07320.10
7.0.00.0030.07020.14
5.6.280.0070.06721.00
5.6.250.0070.08020.79
5.6.240.0030.07020.61
5.6.230.0100.06320.64
5.6.220.0070.08320.66
5.6.210.0100.04720.62
5.6.200.0100.03721.05
5.6.190.0030.08320.95
5.6.180.0100.08021.05
5.6.170.0070.07021.03
5.6.160.0070.04021.03
5.6.150.0130.08021.15
5.6.140.0100.06721.04
5.6.130.0070.04021.14
5.6.120.0100.10320.95
5.6.110.0030.08321.08
5.6.100.0000.05721.02
5.6.90.0170.05721.00
5.6.80.0070.07720.28
5.6.70.0070.06320.33
5.6.60.0130.07720.46
5.6.50.0070.08020.41
5.6.40.0100.07020.39
5.6.30.0070.04320.39
5.6.20.0030.07720.54
5.6.10.0130.07720.32
5.6.00.0130.07720.30
5.5.380.0130.07720.38
5.5.370.0130.06720.46
5.5.360.0030.09020.36
5.5.350.0130.07320.41
5.5.340.0130.08020.93
5.5.330.0130.07020.89
5.5.320.0100.08020.79
5.5.310.0130.04320.85
5.5.300.0130.07320.66
5.5.290.0030.08720.91
5.5.280.0030.05020.79
5.5.270.0070.05320.73
5.5.260.0030.04720.74
5.5.250.0070.08020.71
5.5.240.0070.04020.23
5.5.230.0070.06020.23
5.5.220.0070.07020.32
5.5.210.0070.07320.32
5.5.200.0170.06320.10
5.5.190.0070.07320.29
5.5.180.0100.06320.29
5.5.160.0000.05320.10
5.5.150.0100.07720.09
5.5.140.0070.08020.11
5.5.130.0100.07320.24
5.5.120.0070.07020.27
5.5.110.0230.06020.24
5.5.100.0130.04720.12
5.5.90.0070.05020.07
5.5.80.0030.06020.08
5.5.70.0070.05320.15
5.5.60.0030.05020.16
5.5.50.0130.04020.16
5.5.40.0100.05020.07
5.5.30.0130.07020.10
5.5.20.0000.07720.09
5.5.10.0130.08020.14
5.5.00.0170.05719.97
5.4.450.0100.07719.54
5.4.440.0100.07319.36
5.4.430.0000.05019.55
5.4.420.0100.08019.41
5.4.410.0100.03319.24
5.4.400.0130.07319.04
5.4.390.0070.07719.05
5.4.380.0030.04719.04
5.4.370.0000.04719.04
5.4.360.0070.07319.00
5.4.350.0070.06719.23
5.4.340.0070.04719.13
5.4.320.0030.08018.90
5.4.310.0100.07318.89
5.4.300.0130.05719.00
5.4.290.0000.05319.05
5.4.280.0030.04719.04
5.4.270.0030.04719.03
5.4.260.0070.06018.90
5.4.250.0030.08018.87
5.4.240.0000.04719.02
5.4.230.0100.05019.15
5.4.220.0100.04718.87
5.4.210.0000.04318.87
5.4.200.0070.04018.89
5.4.190.0100.07719.17
5.4.180.0130.06719.03
5.4.170.0100.07318.84
5.4.160.0030.04719.15
5.4.150.0030.04319.21
5.4.140.0030.04316.58
5.4.130.0100.06316.46
5.4.120.0030.07316.50
5.4.110.0070.06316.52
5.4.100.0000.08316.44
5.4.90.0100.06316.38
5.4.80.0000.05716.43
5.4.70.0070.04016.43
5.4.60.0130.06716.30
5.4.50.0000.04316.23
5.4.40.0100.07316.52
5.4.30.0070.07316.36
5.4.20.0100.06716.47
5.4.10.0070.07016.30
5.4.00.0030.04715.70
5.3.290.0030.05014.69
5.3.280.0030.04314.63
5.3.270.0000.07014.55
5.3.260.0030.05314.61
5.3.250.0100.07714.61
5.3.240.0170.07014.55
5.3.230.0100.04714.68
5.3.220.0130.03314.61
5.3.210.0170.06714.50
5.3.200.0030.07714.55
5.3.190.0130.07714.70
5.3.180.0100.07314.56
5.3.170.0070.07314.51
5.3.160.0070.05014.71
5.3.150.0070.03714.70
5.3.140.0030.07314.56
5.3.130.0100.07014.63
5.3.120.0170.06714.66
5.3.110.0000.08014.55
5.3.100.0030.07714.01
5.3.90.0000.06314.17
5.3.80.0130.07014.04
5.3.70.0130.08014.04
5.3.60.0030.07714.08
5.3.50.0070.07014.01
5.3.40.0000.05714.02
5.3.30.0000.08013.83
5.3.20.0130.06013.73
5.3.10.0070.07313.68
5.3.00.0130.06013.59
5.2.170.0070.03311.06
5.2.160.0000.06311.23
5.2.150.0030.04711.30
5.2.140.0000.07011.27
5.2.130.0100.05710.98
5.2.120.0030.05011.17
5.2.110.0030.05311.05
5.2.100.0070.05011.13
5.2.90.0070.06011.24
5.2.80.0070.05011.11
5.2.70.0030.06311.10
5.2.60.0030.06011.10
5.2.50.0030.06710.96
5.2.40.0100.03711.01
5.2.30.0070.03010.86
5.2.20.0030.03311.11
5.2.10.0070.05310.82
5.2.00.0000.04710.80
5.1.60.0000.05310.41
5.1.50.0070.05310.41
5.1.40.0000.03010.41
5.1.30.0070.05710.43
5.1.20.0030.05710.41
5.1.10.0070.05010.41
5.1.00.0030.03010.41
5.0.50.0030.02010.41
5.0.40.0000.02710.41
5.0.30.0030.03310.41
5.0.20.0030.03710.41
5.0.10.0030.04310.41
5.0.00.0070.06010.41
4.4.90.0030.03710.41
4.4.80.0070.03010.41
4.4.70.0000.04010.41
4.4.60.0000.03710.41
4.4.50.0000.03710.41
4.4.40.0000.02710.41
4.4.30.0030.01310.41
4.4.20.0000.03710.41
4.4.10.0000.02010.41
4.4.00.0000.04010.41
4.3.110.0030.03010.41
4.3.100.0000.03710.41
4.3.90.0000.03010.41
4.3.80.0070.03710.41
4.3.70.0000.04010.41
4.3.60.0000.03710.41
4.3.50.0000.03710.41
4.3.40.0030.05310.41
4.3.30.0000.03710.41
4.3.20.0030.02310.41
4.3.10.0000.02010.41
4.3.00.0070.03310.41

preferences:
95.65 ms | 401 KiB | 5 Q