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; ####################################### # put some data in the StringStreamWrapper $stringstream = StringStreamWrapper::Open($testString); # emulate the output stream (in memory) $output = fopen('php://memory','r+'); # attach write filter to output $filter = stream_filter_append($output, 'convert.base64-encode'); flush($output); # write to output $written = stream_copy_to_stream($stringstream, $output); # remove filter stream_filter_remove($filter); rewind($output); echo "from outputstream = " . stream_get_contents($output).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.3.60.0030.01316.88
8.3.50.0100.01322.18
8.3.40.0150.00018.74
8.3.30.0090.00619.02
8.3.20.0000.00720.27
8.3.10.0030.00523.61
8.3.00.0050.00319.91
8.2.180.0150.00316.86
8.2.170.0120.00322.96
8.2.160.0070.01020.35
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0090.00019.19
8.2.120.0040.00426.35
8.2.110.0030.00620.50
8.2.100.0120.00017.93
8.2.90.0050.00319.34
8.2.80.0040.00417.97
8.2.70.0030.01017.63
8.2.60.0030.00717.91
8.2.50.0030.00618.07
8.2.40.0050.00321.12
8.2.30.0000.00820.65
8.2.20.0000.00817.87
8.2.10.0070.00018.17
8.2.00.0000.00818.28
8.1.280.0120.00325.92
8.1.270.0080.00020.26
8.1.260.0040.00428.09
8.1.250.0030.00528.09
8.1.240.0030.00622.25
8.1.230.0080.00417.78
8.1.220.0080.00017.74
8.1.210.0060.00318.77
8.1.200.0000.00917.35
8.1.190.0040.00417.35
8.1.180.0040.00418.10
8.1.170.0050.00318.66
8.1.160.0030.00620.73
8.1.150.0040.00418.97
8.1.140.0040.00419.66
8.1.130.0040.00417.73
8.1.120.0000.00717.44
8.1.110.0000.00717.47
8.1.100.0080.00017.54
8.1.90.0040.00417.51
8.1.80.0040.00417.45
8.1.70.0030.00517.38
8.1.60.0020.00517.52
8.1.50.0030.00617.53
8.1.40.0030.00617.53
8.1.30.0040.00817.67
8.1.20.0030.00617.62
8.1.10.0060.00317.63
8.1.00.0000.00817.43
8.0.300.0000.00818.77
8.0.290.0000.00717.00
8.0.280.0080.00018.46
8.0.270.0030.00317.36
8.0.260.0030.00317.36
8.0.250.0000.00717.03
8.0.240.0030.00317.05
8.0.230.0000.00717.18
8.0.220.0050.00317.06
8.0.210.0030.00317.09
8.0.200.0030.00317.09
8.0.190.0020.00517.13
8.0.180.0070.00016.96
8.0.170.0080.00017.11
8.0.160.0060.00317.09
8.0.150.0030.00617.00
8.0.140.0040.00416.96
8.0.130.0030.00313.41
8.0.120.0030.00617.07
8.0.110.0000.00816.94
8.0.100.0040.00416.95
8.0.90.0000.00716.90
8.0.80.0070.00817.11
8.0.70.0040.00417.00
8.0.60.0040.00416.94
8.0.50.0050.00217.09
8.0.30.0100.01017.11
8.0.20.0100.01017.41
8.0.10.0040.00417.11
8.0.00.0110.00916.81
7.4.330.0020.00216.84
7.4.320.0030.00316.47
7.4.300.0040.00416.66
7.4.290.0070.00016.61
7.4.280.0050.00616.68
7.4.270.0040.00416.57
7.4.260.0100.00216.53
7.4.250.0000.00816.61
7.4.240.0030.00516.52
7.4.230.0000.00716.49
7.4.220.0160.00816.53
7.4.210.0030.01516.59
7.4.200.0030.00316.63
7.4.160.0060.01016.70
7.4.150.0060.01017.40
7.4.140.0090.01117.86
7.4.130.0140.00516.66
7.4.120.0070.01016.44
7.4.110.0090.00916.59
7.4.100.0130.00316.62
7.4.90.0170.00016.55
7.4.80.0090.00919.39
7.4.70.0090.00916.63
7.4.60.0100.00616.47
7.4.50.0100.00616.50
7.4.40.0170.00016.79
7.4.30.0120.00616.71
7.4.10.0050.01215.18
7.4.00.0100.00614.97
7.3.330.0030.00313.39
7.3.320.0000.00513.49
7.3.310.0040.00416.57
7.3.300.0000.00716.54
7.3.290.0100.00716.50
7.3.280.0110.00716.53
7.3.270.0040.01317.40
7.3.260.0060.01216.43
7.3.250.0110.00816.51
7.3.240.0100.00616.52
7.3.230.0150.00416.65
7.3.210.0060.01016.61
7.3.200.0110.00716.47
7.3.190.0110.00816.54
7.3.180.0140.00716.53
7.3.170.0120.00616.70
7.3.160.0090.00616.35
7.3.130.0060.00814.84
7.3.120.0070.00914.92
7.3.110.0120.00614.80
7.3.100.0100.00514.98
7.3.90.0090.00614.88
7.3.80.0050.00914.96
7.3.70.0090.00314.99
7.3.60.0030.01214.99
7.3.50.0030.01014.95
7.3.40.0050.00914.85
7.3.30.0090.00314.82
7.3.20.0060.00816.85
7.3.10.0060.01016.79
7.3.00.0080.00516.80
7.2.330.0090.00916.86
7.2.320.0100.01416.95
7.2.310.0090.01016.55
7.2.300.0070.01016.79
7.2.290.0000.02116.56
7.2.260.0050.01415.12
7.2.250.0090.00915.22
7.2.240.0060.01015.05
7.2.230.0090.00915.08
7.2.220.0080.00615.24
7.2.210.0070.00714.89
7.2.200.0050.01115.24
7.2.190.0050.00915.28
7.2.180.0080.00314.98
7.2.170.0090.00515.15
7.2.160.0040.00515.26
7.2.150.0010.01216.88
7.2.140.0050.00817.05
7.2.130.0050.00517.05
7.2.120.0060.00716.86
7.2.110.0070.00916.97
7.2.100.0100.00916.97
7.2.90.0060.01016.95
7.2.80.0090.00516.95
7.2.70.0070.00516.97
7.2.60.0040.01017.03
7.2.50.0050.00716.93
7.2.40.0030.01416.95
7.2.30.0060.01016.97
7.2.20.0100.00716.90
7.2.10.0080.00917.04
7.2.00.0050.00817.87
7.1.330.0040.01015.88
7.1.320.0060.00715.82
7.1.310.0060.00515.97
7.1.300.0060.00915.80
7.1.290.0020.01015.71
7.1.280.0090.00515.97
7.1.270.0020.01215.77
7.1.260.0040.01015.77
7.1.250.0020.01215.80
7.1.240.0070.00515.82
7.1.230.0050.00915.76
7.1.220.0080.00715.94
7.1.210.0020.01215.89
7.1.200.0040.00715.85
7.1.190.0020.00715.82
7.1.180.0050.00915.70
7.1.170.0070.00515.84
7.1.160.0060.01015.83
7.1.150.0050.00816.01
7.1.140.0030.00715.93
7.1.130.0060.00815.98
7.1.120.0000.01315.65
7.1.110.0030.00915.88
7.1.100.0050.00816.70
7.1.90.0080.00515.77
7.1.80.0060.00715.72
7.1.70.0060.00616.29
7.1.60.0070.00916.97
7.1.50.0060.00816.21
7.1.40.0090.00415.82
7.1.30.0070.00715.93
7.1.20.0030.01215.85
7.1.10.0030.00815.76
7.1.00.0020.03117.92
7.0.330.0070.00315.30
7.0.320.0050.01015.41
7.0.310.0060.00615.58
7.0.300.0090.00415.42
7.0.290.0030.00915.24
7.0.280.0040.00715.36
7.0.270.0030.01015.56
7.0.260.0050.00615.33
7.0.250.0070.00515.42
7.0.240.0070.00515.57
7.0.230.0050.00815.40
7.0.220.0020.01115.54
7.0.210.0030.01215.49
7.0.200.0050.00715.76
7.0.190.0030.01215.54
7.0.180.0090.00515.55
7.0.170.0050.01215.46
7.0.160.0080.00715.30
7.0.150.0030.00515.53
7.0.140.0060.00815.36
7.0.130.0040.00815.33
7.0.120.0090.00615.51
7.0.110.0070.00415.45
7.0.100.0050.00515.48
7.0.90.0070.00615.37
7.0.80.0050.00815.42
7.0.70.0050.01115.38
7.0.60.0070.01717.01
7.0.50.0040.03316.29
7.0.40.0070.03315.73
7.0.30.0220.02115.76
7.0.20.0160.03015.73
7.0.10.0030.02415.69
7.0.00.0060.02815.70
5.6.400.0060.00614.71
5.6.390.0050.00914.50
5.6.380.0070.00314.47
5.6.370.0040.00914.46
5.6.360.0090.00514.61
5.6.350.0030.01214.65
5.6.340.0070.00714.63
5.6.330.0090.00514.58
5.6.320.0050.00814.58
5.6.310.0030.00714.68
5.6.300.0070.00414.37
5.6.290.0050.01014.63
5.6.280.0050.02516.88
5.6.270.0030.01214.42
5.6.260.0050.00714.83
5.6.250.0020.00914.41
5.6.240.0030.01214.62
5.6.230.0080.00814.58
5.6.220.0080.00814.56
5.6.210.0100.02316.56
5.6.200.0080.01515.89
5.6.190.0040.02516.59
5.6.180.0090.02416.68
5.6.170.0080.02016.51
5.6.160.0100.03216.68
5.6.150.0040.01915.83
5.6.140.0020.03015.81
5.6.130.0100.02715.85
5.6.120.0080.01916.69
5.6.110.0060.03416.78
5.6.100.0070.01816.59
5.6.90.0090.02516.52
5.6.80.0040.01916.52
5.6.70.0030.01014.51
5.6.60.0040.00714.31
5.6.50.0020.00814.48
5.6.40.0110.00314.53
5.6.30.0050.00714.41
5.6.20.0050.00514.44
5.6.10.0060.00814.55
5.6.00.0050.01114.63
5.5.380.0090.00414.66
5.5.370.0060.00614.67
5.5.360.0040.00714.55
5.5.350.0140.02816.59
5.5.340.0090.03115.65
5.5.330.0040.02416.50
5.5.320.0080.01816.43
5.5.310.0090.02216.52
5.5.300.0030.01915.73
5.5.290.0090.02715.74
5.5.280.0060.03316.57
5.5.270.0080.03316.54
5.5.260.0070.02116.60
5.5.250.0050.02616.61
5.5.240.0110.03016.43
5.5.230.0030.00714.33
5.5.220.0030.00814.30
5.5.210.0070.00914.46
5.5.200.0050.00614.36
5.5.190.0070.00714.39
5.5.180.0030.01014.34
5.5.170.0030.00714.38
5.5.160.0070.00314.17
5.5.150.0070.00414.45
5.5.140.0030.01314.54
5.5.130.0050.00714.34
5.5.120.0070.00814.38
5.5.110.0080.00914.49
5.5.100.0080.00614.52
5.5.90.0050.01014.46
5.5.80.0040.01114.59
5.5.70.0090.00414.52
5.5.60.0070.00714.65
5.5.50.0030.01014.37
5.5.40.0090.00714.23
5.5.30.0070.00814.49
5.5.20.0070.01014.36
5.5.10.0030.00814.37
5.5.00.0070.00714.36

preferences:
47.73 ms | 401 KiB | 5 Q