3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace owasp\csp; class ContentSecurityPolicy { const DEFAULT_SRC = 'default-src'; const SCRIPT_SRC = 'script-src'; const OBJECT_SRC = 'object-src'; const STYLE_SRC = 'style-src'; const IMG_SRC = 'img-src'; const MEDIA_SRC = 'media-src'; const FRAME_SRC = 'frame-src'; const FONT_SRC = 'font-src'; const CONNECT_SRC = 'connect-src'; const SOURCE_NONE = "'none'"; const SOURCE_SELF = "'self'"; const SOURCE_UNSAFE_INLINE = "'unsafe-inline'"; const SOURCE_UNSAFE_EVAL = "'unsafe-eval'"; private $policy; public function __construct() { $this->policy = array(); $this->setPolicySourceDirectives(); } private function setPolicySourceDirectives(){ $refl = new ReflectionClass(__CLASS__); $srcPattern = '/.+_SRC$/'; foreach ($refl->getConstants() as $constant => $value){ if (preg_match($srcPattern, $constant)){ $this->policy[constant(__CLASS__.'::'.$constant)] = array(); } } } private function copy() { $retval = new ContentSecurityPolicy(); foreach ($this->policy as $directive => $sources) { foreach ($sources as $source) { array_push($retval->policy[$directive], $source); } } return $retval; } function addSource($directive, $source) { if (!isset($this->policy[$directive])) { throw new CSPException("Invalid directive"); } $this->policy[$directive][] = $source; return $this; } function toString() { return $this->__toString(); } public function __toString(){ $retval = array(); foreach ($this->policy as $directive => $sources) { if (sizeof($sources) > 0) { $retval[] = join(' ', array($directive, join(' ', $sources))); } } return 'Content-Security-Policy: ' . join('; ', $retval); } } class CSPException extends \Exception {} use owasp\csp\ContentSecurityPolicy as CSP; $csp = new CSP(); $csp->addSource(CSP::DEFAULT_SRC, CSP::SOURCE_SELF) ->addSource(CSP::SCRIPT_SRC, CSP::SOURCE_SELF) ->addSource(CSP::SCRIPT_SRC, 'http://code.jquery.com') ->addSource(CSP::STYLE_SRC, ContentSecurityPolicy::SOURCE_SELF) ->addSource(CSP::STYLE_SRC, 'https://bootstrapcdn.com') ->addSource(CSP::FONT_SRC, 'https://fonts.googleapis.com'); echo $csp->toString(); exit("\nDone!\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)
8.3.70.0140.00416.88
8.3.60.0070.00718.27
8.3.50.0110.00821.20
8.3.40.0170.00318.79
8.3.30.0000.01520.11
8.3.20.0040.00420.34
8.3.10.0110.00421.87
8.3.00.0040.00422.51
8.2.180.0100.01016.88
8.2.170.0160.00622.96
8.2.160.0100.00322.08
8.2.150.0040.00424.18
8.2.140.0070.00324.66
8.2.130.0040.00426.16
8.2.120.0000.00820.77
8.2.110.0000.00922.20
8.2.100.0030.00917.97
8.2.90.0000.00819.13
8.2.80.0040.00419.21
8.2.70.0030.00617.63
8.2.60.0000.00817.91
8.2.50.0030.00518.07
8.2.40.0080.00018.21
8.2.30.0020.00519.48
8.2.20.0040.00417.65
8.2.10.0080.00017.70
8.2.00.0000.00817.84
8.1.280.0030.01425.92
8.1.270.0030.00623.99
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0030.00620.54
8.1.230.0070.00418.94
8.1.220.0080.00017.77
8.1.210.0000.00818.77
8.1.200.0090.00017.35
8.1.190.0000.00817.55
8.1.180.0050.00318.10
8.1.170.0080.00018.50
8.1.160.0050.00518.92
8.1.150.0040.00418.60
8.1.140.0020.00517.38
8.1.130.0070.00017.82
8.1.120.0000.00717.42
8.1.110.0020.00517.51
8.1.100.0040.00417.41
8.1.90.0050.00317.50
8.1.80.0000.00817.46
8.1.70.0030.00317.47
8.1.60.0040.00417.58
8.1.50.0040.00417.53
8.1.40.0090.00317.54
8.1.30.0000.00817.73
8.1.20.0040.00417.66
8.1.10.0000.00817.59
8.1.00.0050.00317.63
8.0.300.0000.00818.77
8.0.290.0080.00017.30
8.0.280.0000.00718.49
8.0.270.0030.00317.19
8.0.260.0050.00517.04
8.0.250.0030.00317.04
8.0.240.0030.00516.99
8.0.230.0030.00317.06
8.0.220.0030.00316.97
8.0.210.0030.00317.02
8.0.200.0030.00316.94
8.0.190.0000.00717.05
8.0.180.0070.00017.05
8.0.170.0000.00716.90
8.0.160.0070.00016.88
8.0.150.0000.00716.96
8.0.140.0030.00616.86
8.0.130.0050.00013.40
8.0.120.0060.00317.01
8.0.110.0030.00516.98
8.0.100.0000.00717.00
8.0.90.0040.00416.85
8.0.80.0100.00616.95
8.0.70.0040.00416.96
8.0.60.0000.00717.04
8.0.50.0020.00516.86
8.0.30.0100.01217.21
8.0.20.0070.01017.40
8.0.10.0000.00717.01
8.0.00.0090.01316.93
7.4.330.0020.00216.85
7.4.320.0070.00016.38
7.4.300.0060.00016.49
7.4.290.0030.00316.46
7.4.280.0070.00016.46
7.4.270.0030.00516.57
7.4.260.0000.00513.22
7.4.250.0000.00716.42
7.4.240.0020.00516.51
7.4.230.0000.00816.44
7.4.220.0150.00416.59
7.4.210.0090.00516.60
7.4.200.0040.00416.26
7.4.190.0000.00716.70
7.4.160.0060.01016.56
7.4.150.0100.00717.40
7.4.140.0120.00517.86
7.4.130.0100.01116.43
7.4.120.0100.00716.60
7.4.110.0150.00316.54
7.4.100.0070.01016.52
7.4.90.0000.01616.59
7.4.80.0150.00319.39
7.4.70.0100.00616.43
7.4.60.0060.01016.39
7.4.50.0000.00516.68
7.4.40.0060.00622.77
7.4.30.0040.01816.45
7.4.00.0050.01114.98
7.3.330.0050.00013.29
7.3.320.0000.00613.27
7.3.310.0070.00016.31
7.3.300.0000.00716.29
7.3.290.0110.00416.36
7.3.280.0090.00916.38
7.3.270.0110.00617.40
7.3.260.0120.00918.24
7.3.250.0080.01016.38
7.3.240.0070.01016.29
7.3.230.0130.00316.57
7.3.210.0100.00716.36
7.3.200.0120.00619.39
7.3.190.0150.00316.37
7.3.180.0120.00416.58
7.3.170.0060.01216.64
7.3.160.0070.01016.58
7.3.120.0080.00814.85
7.3.110.0090.00914.79
7.3.100.0070.00914.89
7.3.90.0100.00514.75
7.3.80.0060.00914.86
7.3.70.0060.00514.79
7.3.60.0050.00914.90
7.3.50.0040.01114.81
7.3.40.0080.00514.92
7.3.30.0060.01015.02
7.3.20.0060.00916.59
7.3.10.0040.00816.72
7.3.00.0060.00816.65
7.2.330.0040.01416.67
7.2.320.0100.00716.54
7.2.310.0070.01116.39
7.2.300.0110.00716.38
7.2.290.0060.01216.59
7.2.250.0110.00814.91
7.2.240.0120.00915.02
7.2.230.0060.00714.95
7.2.220.0050.00915.05
7.2.210.0060.00815.13
7.2.200.0090.00315.05
7.2.190.0090.00714.82
7.2.180.0060.00514.88
7.2.170.0050.00714.98
7.2.130.0000.01617.06
7.2.120.0060.00616.75
7.2.110.0040.01116.76
7.2.100.0040.00816.79
7.2.90.0030.00616.67
7.2.80.0000.01216.86
7.2.70.0040.00816.61
7.2.60.0070.00516.56
7.2.50.0060.01016.73
7.2.40.0000.01216.86
7.2.30.0040.00416.82
7.2.20.0000.01516.98
7.2.10.0030.00716.78
7.2.00.0070.00517.89
7.1.330.0020.01215.60
7.1.320.0010.00915.69
7.1.310.0050.00715.73
7.1.300.0090.00415.66
7.1.290.0030.01015.55
7.1.280.0080.00515.58
7.1.270.0040.00715.65
7.1.260.0040.01115.57
7.1.250.0100.00615.74
7.1.200.0000.01215.54
7.1.100.0000.01018.13
7.1.70.0000.00817.07
7.1.60.0070.01719.17
7.1.50.0030.02016.86
7.1.00.0000.07722.45
7.0.200.0760.00314.91
7.0.140.0030.09722.15
7.0.90.0670.07720.01
7.0.80.0430.04720.00
7.0.70.0570.08320.03
7.0.60.0430.05019.93
7.0.50.0500.08320.38
7.0.40.0130.08019.95
7.0.30.0000.09720.06
7.0.20.0170.08020.11
7.0.10.0130.04320.07
7.0.00.0100.07719.99
5.6.280.0030.07320.93
5.6.230.0100.03720.65
5.6.220.0130.07320.76
5.6.210.0070.08020.65
5.6.200.0030.08721.07
5.6.190.0100.08320.95
5.6.180.0100.08021.04
5.6.170.0100.08021.11
5.6.160.0030.07321.20
5.6.150.0100.05721.16
5.6.140.0170.06721.02
5.6.130.0100.08720.95
5.6.120.0070.04320.96
5.6.110.0200.07021.05
5.6.100.0170.06720.97
5.6.90.0070.08721.06
5.6.80.0070.07720.36
5.6.70.0030.05320.41
5.6.60.0030.06720.46
5.6.50.0070.08020.32
5.6.40.0100.05020.41
5.6.30.0100.07720.41
5.6.20.0130.04020.40
5.6.10.0130.07320.38
5.6.00.0100.04720.47
5.5.370.0130.06720.49
5.5.360.0070.06720.51
5.5.350.0100.07720.35
5.5.340.0000.09020.86
5.5.330.0070.08320.95
5.5.320.0100.08320.94
5.5.310.0100.08320.95
5.5.300.0070.07720.79
5.5.290.0170.04720.91
5.5.280.0070.08020.85
5.5.270.0100.08320.84
5.5.260.0000.08320.91
5.5.250.0070.05320.66
5.5.240.0030.04720.31
5.5.230.0100.04320.16
5.5.220.0070.08320.04
5.5.210.0030.05720.04
5.5.200.0200.06320.25
5.5.190.0030.05720.26
5.5.180.0200.06320.21
5.5.160.0030.08320.26
5.5.150.0030.08720.13
5.5.140.0000.08320.22
5.5.130.0130.07020.30
5.5.120.0100.07320.17
5.5.110.0030.06020.19
5.5.100.0070.08020.10
5.5.90.0130.07020.11
5.5.80.0030.07720.18
5.5.70.0100.03720.08
5.5.60.0100.05020.12
5.5.50.0100.07320.08
5.5.40.0070.06020.08
5.5.30.0130.06720.09
5.5.20.0070.07020.13
5.5.10.0130.04719.98
5.5.00.0100.07720.12
5.4.450.0100.07719.38
5.4.440.0130.06019.44
5.4.430.0030.07719.22
5.4.420.0100.05319.34
5.4.410.0030.04719.28
5.4.400.0170.06719.23
5.4.390.0100.06319.12
5.4.380.0130.06719.18
5.4.370.0030.08018.95
5.4.360.0070.06719.23
5.4.350.0030.07719.09
5.4.340.0130.07319.12
5.4.320.0070.04319.18
5.4.310.0070.05319.03
5.4.300.0070.07319.09
5.4.290.0100.07019.20
5.4.280.0070.05019.04
5.4.270.0070.07318.90
5.4.260.0070.08019.04
5.4.250.0100.04319.08
5.4.240.0030.04019.08
5.4.230.0130.06719.03
5.4.220.0170.07019.13
5.4.210.0000.04718.84
5.4.200.0070.08018.87
5.4.190.0070.04319.03
5.4.180.0030.05019.02
5.4.170.0100.05019.21
5.4.160.0100.07018.88
5.4.150.0070.08019.02
5.4.140.0070.07316.38
5.4.130.0030.04716.37
5.4.120.0070.06316.50
5.4.110.0000.06016.45
5.4.100.0170.06316.48
5.4.90.0030.07016.41
5.4.80.0030.08016.55
5.4.70.0130.04316.37
5.4.60.0070.07716.48
5.4.50.0030.07316.48
5.4.40.0170.06316.37
5.4.30.0100.04316.26
5.4.20.0100.06716.37
5.4.10.0030.07316.39
5.4.00.0030.06015.89
5.3.290.0030.05714.69
5.3.280.0100.07014.55
5.3.270.0000.04714.60
5.3.260.0070.08014.75
5.3.250.0030.05014.73
5.3.240.0030.07714.74
5.3.230.0170.07014.71
5.3.220.0030.05314.68
5.3.210.0030.08314.54
5.3.200.0100.07014.65
5.3.190.0130.06714.60
5.3.180.0070.07314.55
5.3.170.0200.06714.69
5.3.160.0130.07014.56
5.3.150.0070.07314.64
5.3.140.0100.07314.65
5.3.130.0030.07714.50
5.3.120.0070.07714.66
5.3.110.0130.07014.63
5.3.100.0130.05014.13
5.3.90.0100.03314.07
5.3.80.0070.05314.16
5.3.70.0030.07714.16
5.3.60.0100.07014.15
5.3.50.0100.06713.95
5.3.40.0130.06014.02
5.3.30.0070.07014.00
5.3.20.0000.06713.71
5.3.10.0070.05013.71
5.3.00.0030.07313.71
5.2.170.0070.05313.71
5.2.160.0100.05713.71
5.2.150.0170.05713.71
5.2.140.0070.04713.71
5.2.130.0000.04013.71
5.2.120.0100.05713.71
5.2.110.0070.04313.71
5.2.100.0100.05313.71
5.2.90.0030.06713.71
5.2.80.0000.05013.71
5.2.70.0070.03313.71
5.2.60.0030.06313.71
5.2.50.0030.05313.71
5.2.40.0030.06013.71
5.2.30.0070.04013.71
5.2.20.0100.05713.71
5.2.10.0070.05013.71
5.2.00.0000.04313.71
5.1.60.0000.05713.71
5.1.50.0070.04713.71
5.1.40.0000.04713.71
5.1.30.0130.04713.71
5.1.20.0100.05013.71
5.1.10.0070.04713.71
5.1.00.0070.05013.71
5.0.50.0000.05013.71
5.0.40.0100.02713.71
5.0.30.0030.06313.71
5.0.20.0070.02713.71
5.0.10.0070.04013.71
5.0.00.0000.06313.71
4.4.90.0030.03713.71
4.4.80.0030.02013.71
4.4.70.0000.03713.71
4.4.60.0030.02713.71
4.4.50.0000.03013.71
4.4.40.0000.05713.71
4.4.30.0000.03713.71
4.4.20.0070.02013.71
4.4.10.0070.02313.71
4.4.00.0000.04713.71
4.3.110.0030.03013.71
4.3.100.0130.01713.71
4.3.90.0000.02013.71
4.3.80.0030.05313.71
4.3.70.0030.02313.71
4.3.60.0030.03313.71
4.3.50.0030.03313.71
4.3.40.0030.03713.71
4.3.30.0030.03313.71
4.3.20.0000.03313.71
4.3.10.0000.03313.71
4.3.00.0030.03313.71

preferences:
41.76 ms | 401 KiB | 5 Q