3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringStreamWrapper { const PROTOCOL = "stringstream"; private $stringstream; private $position; private $stringlength; public function stream_open($path, $mode, $options, &$opened_path) { $contextOptions = stream_context_get_options($this->context); if (!isset($contextOptions[self::PROTOCOL]['string'])) return false; $this->position = 0; // this is our stream! $this->stringstream = $contextOptions[self::PROTOCOL]['string']; $this->stringlength = strlen($this->stringstream); return true; } public function stream_read($len) { $data = substr($this->stringstream, $this->position, $len); $this->position += strlen($data); return $data; } public function stream_write($data){ $l = strlen($data); $this->stringstream = substr($this->stringstream, 0, $this->position) . $data . substr($this->stringstream, $this->position += $l); $this->stringlength = strlen($this->stringstream); return $l; } public function stream_seek($offset, $whence = SEEK_SET) { if ($whence == SEEK_CUR) { $this->position += $offset; } else if ($whence == SEEK_END) { $this->position = $this->stringlength + $offset; } else { $this->position = $offset; } return true; } public function stream_tell() { return $this->position; } public function stream_eof() { return ($this->position >= $this->stringlength); } public function stream_stat() { return array( 7 => $this->stringlength, 'size' => $this->stringlength, ); } static public function Open($string) { $context = stream_context_create(array(self::PROTOCOL => array('string' => &$string))); return fopen(self::PROTOCOL . "://",'r', false, $context); } } stream_wrapper_register(StringStreamWrapper::PROTOCOL, "StringStreamWrapper"); class replace_nullchar_filter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $bucket->data = str_replace("\0", "", $bucket->data); $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } stream_filter_register('replacenullchar', 'replace_nullchar_filter'); class StringStreamWrapperFixed { public static function bug68532fixed() { if (defined('BUG68532FIXED')) return BUG68532FIXED; return version_compare(PHP_VERSION, '5.6.5', '>=') || (version_compare(PHP_VERSION, '5.5.21', '>=') && version_compare(PHP_VERSION, '5.6.0', '<')); } public static function Open($string) { if (self::bug68532fixed()) { $stream = fopen('php://temp', 'r+'); } else { $stream = tmpfile(); } fwrite($stream, $string); rewind($stream); return $stream; } } ####################################### $testString = 'test'; echo "base64_encode = " . base64_encode($testString).PHP_EOL; ####################################### echo "StringStreamWrapper write filter 1 = "; $stream = StringStreamWrapper::Open(""); $filter = stream_filter_append($stream, 'convert.base64-encode'); fwrite($stream, $testString); stream_filter_remove($filter); rewind($stream); fpassthru($stream); fclose($stream); echo PHP_EOL; ####################################### $stream = StringStreamWrapper::Open(""); $filter = stream_filter_append($stream, 'convert.base64-encode', STREAM_FILTER_WRITE); fwrite($stream, $testString); stream_filter_remove($filter); rewind($stream); echo "StringStreamWrapper write filter 2 = "; fpassthru($stream); fclose($stream); echo PHP_EOL; ####################################### echo "StringStreamWrapper read filter 1 = "; $stream = StringStreamWrapper::Open(""); fwrite($stream, $testString); $filter = stream_filter_append($stream, 'convert.base64-encode'); rewind($stream); fpassthru($stream); stream_filter_remove($filter); fclose($stream); echo PHP_EOL; ####################################### echo "StringStreamWrapper read filter 2 = "; $stream = StringStreamWrapper::Open(""); fwrite($stream, $testString); $filter = stream_filter_append($stream, 'convert.base64-encode', STREAM_FILTER_READ); rewind($stream); fpassthru($stream); stream_filter_remove($filter); fclose($stream); echo PHP_EOL;

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.5.20.0070.00320.26
8.5.10.0110.00720.09
8.5.00.0140.00920.39
8.4.170.0180.01022.25
8.4.160.0100.01323.80
8.4.150.0060.00617.00
8.4.140.0100.01117.65
8.4.130.0140.00817.62
8.4.120.0080.00524.06
8.4.110.0110.00920.70
8.4.100.0120.00418.77
8.4.90.0140.00920.34
8.4.80.0040.00718.91
8.4.70.0120.00820.60
8.4.60.0100.01018.91
8.4.50.0080.00718.88
8.4.40.0060.00318.82
8.4.30.0130.00719.34
8.4.20.0060.01618.02
8.4.10.0100.00717.82
8.3.290.0110.01020.88
8.3.280.0060.00617.17
8.3.270.0090.01016.70
8.3.260.0090.01216.85
8.3.250.0050.00317.31
8.3.240.0130.00617.25
8.3.230.0100.01016.61
8.3.220.0100.00819.17
8.3.210.0080.00718.70
8.3.200.0040.00716.80
8.3.190.0090.00717.41
8.3.180.0090.01017.22
8.3.170.0130.00722.43
8.3.160.0110.00717.32
8.3.150.0110.00716.68
8.3.140.0080.00016.86
8.3.130.0040.00416.86
8.3.120.0040.00419.10
8.3.110.0080.00320.94
8.3.100.0100.00716.86
8.3.90.0040.00418.42
8.3.80.0100.00317.97
8.3.70.0060.01016.75
8.3.60.0110.00717.00
8.3.50.0070.01221.95
8.3.40.0090.00618.83
8.3.30.0040.01118.84
8.3.20.0040.00420.34
8.3.10.0050.00323.70
8.3.00.0050.00319.79
8.2.300.0120.00918.19
8.2.290.0110.00720.25
8.2.280.0150.00618.82
8.2.270.0150.00416.89
8.2.260.0090.00617.21
8.2.250.0170.00316.76
8.2.240.0100.00617.16
8.2.230.0060.00322.58
8.2.220.0050.00324.06
8.2.210.0080.00826.77
8.2.200.0060.00318.29
8.2.190.0130.00616.63
8.2.180.0090.00918.29
8.2.170.0070.00722.96
8.2.160.0070.01020.52
8.2.150.0090.00624.18
8.2.140.0040.00424.66
8.2.130.0040.00821.13
8.2.120.0030.00626.35
8.2.110.0000.00920.50
8.2.100.0000.01217.91
8.2.90.0050.00319.21
8.2.80.0030.00717.97
8.2.70.0030.00617.63
8.2.60.0050.00318.03
8.2.50.0060.00318.07
8.2.40.0070.00320.43
8.2.30.0040.00420.67
8.2.20.0050.00217.87
8.2.10.0000.00818.19
8.2.00.0040.00418.10
8.1.340.0130.00817.70
8.1.330.0100.00922.24
8.1.320.0100.01016.55
8.1.310.0120.00016.79
8.1.300.0070.01116.86
8.1.290.0000.00918.88
8.1.280.0110.00425.92
8.1.270.0040.00423.99
8.1.260.0040.00428.09
8.1.250.0080.00028.09
8.1.240.0090.00023.82
8.1.230.0040.00723.98
8.1.220.0050.00317.88
8.1.210.0040.00418.77
8.1.200.0000.00917.48
8.1.190.0050.00317.48
8.1.180.0030.00618.10
8.1.170.0030.00618.83
8.1.160.0000.00720.83
8.1.150.0040.00418.88
8.1.140.0040.00419.54
8.1.130.0030.00317.75
8.1.120.0080.00017.54
8.1.110.0040.00417.52
8.1.100.0030.00617.52
8.1.90.0000.00717.54
8.1.80.0040.00417.43
8.1.70.0040.00417.46
8.1.60.0000.00817.68
8.1.50.0060.00317.54
8.1.40.0030.00617.61
8.1.30.0060.00317.75
8.1.20.0030.00517.56
8.1.10.0030.00617.66
8.1.00.0050.00317.61
8.0.300.0040.00418.77
8.0.290.0000.00916.88
8.0.280.0070.00018.61
8.0.270.0070.00017.26
8.0.260.0060.00017.42
8.0.250.0070.00017.04
8.0.240.0000.00717.09
8.0.230.0030.00316.98
8.0.220.0090.00016.93
8.0.210.0040.00417.00
8.0.200.0060.00316.96
8.0.190.0060.00317.01
8.0.180.0000.00716.89
8.0.170.0050.00316.95
8.0.160.0000.00817.10
8.0.150.0040.00817.02
8.0.140.0000.00716.95
8.0.130.0030.00313.37
8.0.120.0090.00016.91
8.0.110.0040.00417.02
8.0.100.0000.00817.13
8.0.90.0050.00217.00
8.0.80.0080.00816.95
8.0.70.0050.00316.96
8.0.60.0000.00716.99
8.0.50.0040.00416.99
8.0.30.0140.00517.16
8.0.20.0070.01317.40
8.0.10.0040.00416.95
8.0.00.0130.00916.76
7.4.330.0020.00216.83
7.4.320.0030.00316.66
7.4.300.0030.00616.58
7.4.290.0000.00816.51
7.4.280.0000.00916.51
7.4.270.0000.00716.52
7.4.260.0030.00916.67
7.4.250.0000.00816.66
7.4.240.0020.00516.55
7.4.230.0000.00716.74
7.4.220.0130.00716.65
7.4.210.0120.00316.59
7.4.200.0080.00016.68
7.4.160.0100.00716.53
7.4.150.0090.00917.40
7.4.140.0130.01117.86
7.4.130.0150.00716.60
7.4.120.0090.00916.49
7.4.110.0060.01216.68
7.4.100.0130.00616.70
7.4.90.0090.00916.66
7.4.80.0090.01219.39
7.4.70.0090.01216.57
7.4.60.0030.01316.63
7.4.50.0070.00716.55
7.4.40.0070.01016.32
7.4.30.0150.01116.59
7.4.00.0070.01115.08
7.3.330.0090.00013.35
7.3.320.0060.00013.44
7.3.310.0070.00016.57
7.3.300.0040.00416.37
7.3.290.0070.00716.47
7.3.280.0110.00716.49
7.3.270.0070.01217.40
7.3.260.0130.00916.64
7.3.250.0100.00916.60
7.3.240.0090.00816.45
7.3.230.0030.01416.52
7.3.210.0100.00716.46
7.3.200.0140.00416.38
7.3.190.0060.01216.73
7.3.180.0060.01116.54
7.3.170.0060.01216.72
7.3.160.0100.01016.66
7.3.120.0060.01314.94
7.3.110.0000.01714.96
7.3.100.0040.01114.82
7.3.90.0050.00315.13
7.3.80.0030.00514.96
7.3.70.0030.01314.77
7.3.60.0090.00614.87
7.3.50.0000.00814.83
7.3.40.0030.00714.86
7.3.30.0040.00715.01
7.3.20.0030.00916.73
7.3.10.0080.01016.61
7.3.00.0120.00716.62
7.2.330.0080.01116.76
7.2.320.0180.00916.95
7.2.310.0090.00916.92
7.2.300.0090.00916.84
7.2.290.0060.01316.66
7.2.250.0000.02015.01
7.2.240.0070.01415.18
7.2.230.0090.00615.07
7.2.220.0060.00314.90
7.2.210.0090.00614.91
7.2.200.0030.00614.93
7.2.190.0100.00315.05
7.2.180.0030.01415.04
7.2.170.0060.01215.34
7.2.160.0090.00615.20
7.2.150.0030.00616.88
7.2.140.0000.01317.02
7.2.130.0130.00616.84
7.2.120.0100.00916.85
7.2.110.0140.00416.75
7.2.100.0080.01016.86
7.2.90.0100.00916.91
7.2.80.0080.01216.87
7.2.70.0110.00617.05
7.2.60.0090.00817.06
7.2.50.0150.00516.97
7.2.40.0120.00717.03
7.2.30.0110.01017.09
7.2.20.0100.00716.96
7.2.10.0040.00816.99
7.2.00.0070.00716.98
7.1.330.0000.01315.57
7.1.320.0060.00615.69
7.1.310.0000.00815.68
7.1.300.0040.00715.69
7.1.290.0030.01316.02
7.1.280.0100.00715.88
7.1.270.0100.00315.89
7.1.260.0030.01315.60
7.1.250.0100.00615.80
7.1.200.0000.01115.77
7.1.70.0000.00717.08
7.1.60.0070.01719.13
7.1.50.0000.01116.74
7.1.00.0000.08022.30
7.0.200.0720.00914.70
7.0.100.0030.04320.00
7.0.90.0000.04720.09
7.0.80.0170.07019.91
7.0.70.0030.05020.04
7.0.60.0100.08019.84
7.0.50.0100.04320.36
7.0.40.0130.07320.04
7.0.30.0030.08320.17
7.0.20.0070.05020.10
7.0.10.0130.07020.07
7.0.00.0070.06020.12
5.6.280.0000.05720.95
5.6.250.0100.07320.79
5.6.240.0100.05720.71
5.6.230.0230.06020.76
5.6.220.0130.06020.63
5.6.210.0100.04720.69
5.6.200.0100.08721.09
5.6.190.0070.08321.08
5.6.180.0070.04021.07
5.6.170.0070.09021.08
5.6.160.0070.08021.01
5.6.150.0070.05021.13
5.6.140.0100.07321.10
5.6.130.0070.04321.12
5.6.120.0030.06321.12
5.6.110.0230.06021.05
5.6.100.0070.06721.05
5.6.90.0000.08021.11
5.6.80.0100.07320.34
5.6.70.0130.07320.42
5.6.60.0070.06320.47
5.6.50.0070.04720.45
5.6.40.0030.04320.57
5.6.30.0070.07020.43
5.6.20.0070.03720.47
5.6.10.0030.04020.42
5.6.00.0070.07020.41
5.5.380.0230.05720.59
5.5.370.0030.05020.46
5.5.360.0030.08720.38
5.5.350.0030.07720.46
5.5.340.0170.07720.88
5.5.330.0070.05020.94
5.5.320.0070.06320.96
5.5.310.0130.05020.93
5.5.300.0100.08020.93
5.5.290.0070.08320.80
5.5.280.0100.04320.93
5.5.270.0130.06720.80
5.5.260.0070.05320.96
5.5.250.0030.08720.73
5.5.240.0070.07320.30
5.5.230.0170.07320.18
5.5.220.0030.05320.31
5.5.210.0100.05720.16
5.5.200.0170.05320.20
5.5.190.0030.04720.22
5.5.180.0000.05020.17
5.5.160.0100.07320.16
5.5.150.0100.04020.29
5.5.140.0100.07720.11
5.5.130.0100.04320.26
5.5.120.0070.04020.25
5.5.110.0070.04020.20
5.5.100.0030.05020.15
5.5.90.0030.05020.16
5.5.80.0000.07720.21
5.5.70.0100.04720.13
5.5.60.0100.03320.16
5.5.50.0130.05320.01
5.5.40.0070.07320.15
5.5.30.0100.06720.20
5.5.20.0200.06720.10
5.5.10.0130.06720.09
5.5.00.0030.07020.07

preferences:
44.14 ms | 403 KiB | 5 Q