3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * This script will generate a pseudo IPv4 in Class E IP space (240.0.0.0 - 255.255.255.255) * for IPv6 users based on the 52 first bits of their IP. Class E address space is reserved * as experimental and no actual traffic should originate from it. * * @author NewEraCracker * @version 2.0.1 * @date 2014/07/03 * @license Public Domain */ var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('::'))); var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('::1'))); var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('::ffff'))); var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('ffff::1:0'))); var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('1::ffff:0'))); var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('1:2:3:4:5:6:7::'))); var_dump(NewEra_IPv6Hack::ip_unpack(NewEra_IPv6Hack::ip_pack('::2:3:4:5:6:7:8'))); class NewEra_IPv6Hack { /** @Link : http://php.net/manual/en/function.inet-pton.php */ public static function ip_pack($ip) { if(strpos($ip, '.') !== false) { // Pack IPv4 $ip = trim($ip, ':f'); $ip = pack('N', ip2long($ip)); return $ip; } elseif(strpos($ip, ':') !== false) { // Expand IPv6 $ip = self::ipv6_expand($ip); // Pack IPv6 $ip = pack('H'.strlen($ip), $ip); return $ip; } return false; } /** @Link : http://php.net/manual/en/function.inet-ntop.php */ public static function ip_unpack($ip) { if(strlen($ip) == 4) { // Unpack IPv4 list(, $ip) = unpack('N', $ip); $ip = long2ip($ip); return $ip; } elseif(strlen($ip) == 16) { // Unpack IPv6 $ip = bin2hex($ip); // Compact IPv6 $res = ''; for($i = strlen($ip); $i > 0; $i = ($i-4)) { $seg = substr($ip, $i-4, 4); $seg = ltrim($seg, '0'); if($seg != '') { $res = $seg.($res==''?'':':').$res; } else { if(strpos($res, '::') === false) { var_dump($i); // Check iteration number to make sure ::1 case is handled if($res != '' && $res[0] == ':' && $i > 4) { continue; } $res = ':'.$res; continue; } $res = '0'.($res==''?'':':').$res; } } // Handle ::2:3:4:5:6:7:8 and 1:2:3:4:5:6:7:: cases if(substr_count($res, ':') == 8) { $res = str_replace('::', ':0:', $res); $res = trim($res, ':'); } return $res; } return false; } /** Expand an IPv6 address */ public static function ipv6_expand($ip) { $ip = explode(':', $ip); $res = ''; $expand = true; foreach($ip as $seg) { if($seg == '' && $expand) { // This will expand a compacted IPv6 $res .= str_pad('', (((8 - count($ip)) + 1) * 4), '0', STR_PAD_LEFT); // Only expand once, otherwise it will cause troubles with ::1 or ffff:: $expand = false; } else { // This will pad to ensure each IPv6 part has 4 digits. $res .= str_pad($seg, 4, '0', STR_PAD_LEFT); } } return $res; } /** Shift an IPv6 to right (IPv6 >> 1). This will be handy to generate a fake IPv4 */ public static function ipv6_shift_right($ip) { $ip = self::ipv6_expand($ip); $ip = substr($ip, -1).substr($ip, 0, -1); $ip = substr(chunk_split($ip, 4, ':'), 0, -1); return $ip; } /** Create a fake IPv4 address from a given IPv6 address */ public static function ipv6_to_ipv4($ip) { if(strpos($ip, ':') === false || strpos($ip, '.') !== false) { return false; } $ip = self::ipv6_shift_right($ip); $ip = self::ip_pack($ip); // First 8 bits of IPv4 will be: // - The last 4 bits of unshifted IPv6, all set to true via mask // - The first 4 bits of unshifted IPv6, all in their original state via mask // This ensures an IPv4 in Class E space (240.0.0.0 - 255.255.255.255) $ipv4 = chr(ord($ip[0]) | 0xf0); for($i=1;$i<7;$i+=2) { // Convert 48 bits of IPv6 in last 24 bits of IPv4 via XOR $ipv4 .= chr(ord($ip[$i]) ^ ord($ip[$i+1])); } return self::ip_unpack($ipv4); } /** Convert a V4overV6 to IPv4 */ public static function v4overv6_to_ipv4($ip) { if(strpos($ip, '.') !== false) { $ip = trim($ip, ':f'); return $ip; } return false; } /** This will test if it is a V4overV6 or an IPv6 and do the convertion */ public static function all_to_ipv4($ip) { $v4overv6_test = self::v4overv6_to_ipv4($ip); if($v4overv6_test !== false) { return $v4overv6_test; } return self::ipv6_to_ipv4($ip); } } ?>

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.0090.00917.00
8.3.50.0050.01422.10
8.3.40.0070.00718.86
8.3.30.0110.00419.03
8.3.20.0000.01020.38
8.3.10.0040.00423.54
8.3.00.0040.00419.14
8.2.180.0040.01116.88
8.2.170.0150.00022.96
8.2.160.0040.01120.47
8.2.150.0040.00424.18
8.2.140.0000.00924.66
8.2.130.0080.00026.16
8.2.120.0080.00020.73
8.2.110.0000.01022.25
8.2.100.0040.00719.52
8.2.90.0030.00519.52
8.2.80.0030.00517.97
8.2.70.0030.00617.63
8.2.60.0000.00817.80
8.2.50.0060.00318.07
8.2.40.0000.00821.01
8.2.30.0040.00418.41
8.2.20.0050.00317.77
8.2.10.0040.00418.29
8.2.00.0060.00317.92
8.1.280.0120.00625.92
8.1.270.0050.00323.88
8.1.260.0030.00626.35
8.1.250.0000.00828.09
8.1.240.0090.00023.85
8.1.230.0040.00818.98
8.1.220.0080.00017.74
8.1.210.0030.00518.77
8.1.200.0070.00317.48
8.1.190.0000.00917.23
8.1.180.0040.00418.10
8.1.170.0040.00418.77
8.1.160.0000.00722.15
8.1.150.0000.00818.72
8.1.140.0080.00017.55
8.1.130.0040.00417.92
8.1.120.0000.00717.54
8.1.110.0000.00817.56
8.1.100.0000.00917.52
8.1.90.0060.00317.48
8.1.80.0000.00717.55
8.1.70.0000.00817.54
8.1.60.0080.00017.73
8.1.50.0080.00017.66
8.1.40.0040.00417.66
8.1.30.0040.00417.81
8.1.20.0000.00817.70
8.1.10.0040.00417.62
8.1.00.0030.00617.61
8.0.300.0040.00418.77
8.0.290.0000.00817.28
8.0.280.0050.00218.53
8.0.270.0070.00017.26
8.0.260.0000.00717.40
8.0.250.0000.00717.08
8.0.240.0000.00717.05
8.0.230.0000.00716.98
8.0.220.0050.00217.05
8.0.210.0000.00716.98
8.0.200.0030.00317.02
8.0.190.0050.00216.95
8.0.180.0030.00517.02
8.0.170.0000.00816.99
8.0.160.0000.00716.94
8.0.150.0050.00216.88
8.0.140.0080.00016.84
8.0.130.0030.00313.39
8.0.120.0030.00516.98
8.0.110.0040.00417.04
8.0.100.0000.00817.10
8.0.90.0000.00816.87
8.0.80.0030.01317.05
8.0.70.0040.00416.95
8.0.60.0050.00316.92
8.0.50.0030.00616.89
8.0.30.0110.00917.08
8.0.20.0110.00817.40
8.0.10.0070.00017.09
8.0.00.0060.01316.82
7.4.330.0000.00615.05
7.4.320.0000.00616.63
7.4.300.0030.00516.50
7.4.290.0040.00416.62
7.4.280.0040.00416.59
7.4.270.0000.00716.67
7.4.260.0000.00716.61
7.4.250.0080.00016.61
7.4.240.0000.00716.63
7.4.230.0040.00416.77
7.4.220.0160.01016.76
7.4.210.0060.00916.55
7.4.200.0070.00016.77
7.4.190.0050.00216.74
7.4.160.0110.00616.49
7.4.150.0120.00817.40
7.4.140.0170.00217.86
7.4.130.0060.01216.54
7.4.120.0070.01516.60
7.4.110.0060.01016.48
7.4.100.0120.01316.60
7.4.90.0130.00716.61
7.4.80.0160.01019.39
7.4.70.0110.00916.80
7.4.60.0120.00616.42
7.4.50.0000.00516.72
7.4.40.0160.00616.52
7.4.30.0100.00816.66
7.4.10.0110.00314.87
7.4.00.0080.00915.03
7.3.330.0030.00313.44
7.3.320.0000.00513.42
7.3.310.0060.00316.45
7.3.300.0070.00016.42
7.3.290.0090.00616.48
7.3.280.0080.01116.44
7.3.270.0160.00317.40
7.3.260.0120.01516.49
7.3.250.0090.01416.57
7.3.240.0120.00916.50
7.3.230.0100.00616.55
7.3.210.0130.01316.86
7.3.200.0100.01019.39
7.3.190.0030.01916.43
7.3.180.0090.00916.65
7.3.170.0100.01316.55
7.3.160.0170.00316.43
7.3.130.0000.01915.15
7.3.120.0110.00814.90
7.3.110.0090.00914.79
7.3.100.0040.01114.80
7.3.90.0170.00014.93
7.3.80.0040.01114.80
7.3.70.0030.01014.86
7.3.60.0000.01314.90
7.3.50.0120.00415.02
7.3.40.0040.01114.76
7.3.30.0060.00614.92
7.3.20.0060.00616.46
7.3.10.0080.00416.69
7.3.00.0030.01016.54
7.2.330.0090.00916.90
7.2.320.0070.01116.82
7.2.310.0110.00716.85
7.2.300.0100.01316.54
7.2.290.0100.01016.55
7.2.260.0070.01415.10
7.2.250.0060.01215.21
7.2.240.0060.01015.07
7.2.230.0040.01114.79
7.2.220.0100.00715.14
7.2.210.0030.00714.94
7.2.200.0030.01315.36
7.2.190.0000.01014.87
7.2.180.0030.01114.83
7.2.170.0080.00715.28
7.2.160.0030.00614.87
7.2.150.0090.00617.10
7.2.140.0080.00417.00
7.2.130.0030.00916.74
7.2.120.0060.00916.91
7.2.110.0030.01016.74
7.2.100.0040.01117.06
7.2.90.0060.00317.02
7.2.80.0090.00016.97
7.2.70.0030.01216.96
7.2.60.0040.00716.79
7.2.50.0090.00316.83
7.2.40.0030.01016.83
7.2.30.0030.01216.97
7.2.20.0000.01617.02
7.2.10.0000.01517.02
7.2.00.0180.00818.08
7.1.330.0120.00415.83
7.1.320.0080.00815.55
7.1.310.0100.00315.54
7.1.300.0120.00315.87
7.1.290.0060.01215.47
7.1.280.0030.00715.48
7.1.270.0030.00615.61
7.1.260.0060.00915.61
7.1.250.0110.00315.90
7.1.240.0000.01415.67
7.1.230.0060.01015.70
7.1.220.0070.01015.79
7.1.210.0030.01015.59
7.1.200.0090.00615.84
7.1.190.0060.00315.79
7.1.180.0030.01015.92
7.1.170.0060.00315.68
7.1.160.0030.00615.82
7.1.150.0000.00915.79
7.1.140.0060.00615.80
7.1.130.0030.00715.93
7.1.120.0030.00615.91
7.1.110.0080.00815.63
7.1.100.0070.00516.94
7.1.90.0000.01715.76
7.1.80.0090.00315.86
7.1.70.0060.00416.35
7.1.60.0060.01117.61
7.1.50.0050.01316.43
7.1.40.0030.00615.41
7.1.30.0060.00315.78
7.1.20.0080.00415.75
7.1.10.0070.00715.89
7.1.00.0070.04019.14
7.0.330.0090.00315.41
7.0.320.0000.00915.43
7.0.310.0060.00915.50
7.0.300.0060.00315.43
7.0.290.0030.01215.38
7.0.280.0040.00715.38
7.0.270.0090.00015.59
7.0.260.0030.00915.55
7.0.250.0000.01715.38
7.0.240.0110.00315.42
7.0.230.0060.00615.09
7.0.220.0030.00515.20
7.0.210.0060.01015.16
7.0.200.0070.01115.95
7.0.190.0030.01215.29
7.0.180.0030.01215.06
7.0.170.0080.00415.06
7.0.160.0060.00915.59
7.0.150.0040.01115.46
7.0.140.0040.04018.77
7.0.130.0090.00315.55
7.0.120.0040.00715.50
7.0.110.0050.00515.29
7.0.100.0170.04417.78
7.0.90.0050.03817.69
7.0.80.0060.02317.67
7.0.70.0060.04417.80
7.0.60.0080.03517.70
7.0.50.0070.02217.85
7.0.40.0110.01716.81
7.0.30.0090.03316.76
7.0.20.0040.04616.86
7.0.10.0070.04416.73
7.0.00.0090.04316.74
5.6.400.0030.01214.64
5.6.390.0030.00814.39
5.6.380.0070.00714.26
5.6.370.0030.01314.13
5.6.360.0040.00814.66
5.6.350.0000.00914.56
5.6.340.0040.01114.31
5.6.330.0070.00714.37
5.6.320.0030.00714.54
5.6.310.0030.00914.59
5.6.300.0040.00714.41
5.6.290.0070.00714.17
5.6.280.0020.04017.75
5.6.270.0080.00314.69
5.6.260.0070.00714.21
5.6.250.0100.02317.69
5.6.240.0020.03017.60
5.6.230.0090.03917.65
5.6.220.0020.02817.42
5.6.210.0090.03017.60
5.6.200.0080.03417.77
5.6.190.0030.02817.58
5.6.180.0080.04217.72
5.6.170.0090.03917.80
5.6.160.0070.04417.75
5.6.150.0050.04217.79
5.6.140.0080.03017.69
5.6.130.0070.03817.67
5.6.120.0050.04617.73
5.6.110.0080.01817.78
5.6.100.0070.03917.67
5.6.90.0050.04517.69
5.6.80.0040.03617.50
5.6.70.0020.04717.39
5.6.60.0100.04017.29
5.6.50.0050.04617.45
5.6.40.0070.03517.38
5.6.30.0050.04217.45
5.6.20.0060.01817.22
5.6.10.0050.03917.38
5.6.00.0090.03217.50
5.5.380.0040.04617.42
5.5.370.0020.02917.46
5.5.360.0100.03517.44
5.5.350.0070.02017.33
5.5.340.0060.03617.65
5.5.330.0050.02717.57
5.5.320.0030.04317.71
5.5.310.0030.04817.42
5.5.300.0030.04517.42
5.5.290.0140.04017.61
5.5.280.0100.01817.67
5.5.270.0020.02517.64
5.5.260.0040.02617.55
5.5.250.0020.04417.55
5.5.240.0000.04117.27
5.5.230.0050.02717.32
5.5.220.0100.02017.16
5.5.210.0100.03017.30
5.5.200.0170.02317.10
5.5.190.0050.03517.15
5.5.180.0050.04317.26
5.5.170.0100.00314.24
5.5.160.0070.04217.24
5.5.150.0050.02017.10
5.5.140.0070.02017.22
5.5.130.0080.01717.21
5.5.120.0060.02817.29
5.5.110.0120.01817.37
5.5.100.0120.02317.17
5.5.90.0070.02817.24
5.5.80.0030.04317.24
5.5.70.0070.03717.11
5.5.60.0070.02317.04
5.5.50.0080.05117.00
5.5.40.0050.03217.28
5.5.30.0050.04417.04
5.5.20.0100.02817.01
5.5.10.0090.03617.23
5.5.00.0020.03416.88
5.4.450.0060.02015.39
5.4.440.0050.04515.28
5.4.430.0080.01815.31
5.4.420.0030.02815.15
5.4.410.0020.02815.06
5.4.400.0070.04015.05
5.4.390.0030.03814.99
5.4.380.0120.03715.05
5.4.370.0030.02215.01
5.4.360.0080.04015.09
5.4.350.0070.02815.06
5.4.340.0050.02414.99
5.4.330.0000.01211.22
5.4.320.0090.03815.16
5.4.310.0060.04214.99
5.4.300.0080.04115.25
5.4.290.0070.02315.20
5.4.280.0000.03314.95
5.4.270.0020.02515.21
5.4.260.0070.04215.20
5.4.250.0050.03814.87
5.4.240.0030.04214.99
5.4.230.0080.03915.02
5.4.220.0040.03315.11
5.4.210.0060.02915.00
5.4.200.0100.02515.09
5.4.190.0020.02014.93
5.4.180.0050.03615.10
5.4.170.0060.04115.13
5.4.160.0020.03815.04
5.4.150.0030.03615.00
5.4.140.0050.04513.65
5.4.130.0130.01013.96
5.4.120.0020.02313.99
5.4.110.0020.02313.81
5.4.100.0080.03813.64
5.4.90.0030.04114.00
5.4.80.0050.03913.79
5.4.70.0050.03913.91
5.4.60.0050.02713.74
5.4.50.0050.04013.85
5.4.40.0050.04313.78
5.4.30.0030.04213.84
5.4.20.0030.04213.82
5.4.10.0030.02013.79
5.4.00.0070.03613.59
5.3.290.0030.02612.74
5.3.280.0030.02012.53
5.3.270.0080.03312.53
5.3.260.0070.03712.68
5.3.250.0050.02212.76
5.3.240.0030.04012.64
5.3.230.0030.02512.69
5.3.220.0030.02512.60
5.3.210.0070.02212.45
5.3.200.0030.02612.64
5.3.190.0040.04012.66
5.3.180.0030.03612.69
5.3.170.0080.02312.74
5.3.160.0030.03312.61
5.3.150.0030.04212.68
5.3.140.0030.03412.71
5.3.130.0070.04012.54
5.3.120.0030.02512.61
5.3.110.0070.03312.63
5.3.100.0090.03812.42
5.3.90.0030.02112.44
5.3.80.0080.03812.23
5.3.70.0050.02512.32
5.3.60.0060.02012.31
5.3.50.0090.03812.25
5.3.40.0060.03812.27
5.3.30.0070.01712.25
5.3.20.0020.04412.20
5.3.10.0070.01512.08
5.3.00.0050.04312.06

preferences:
40.15 ms | 400 KiB | 5 Q