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); fwrite($output, $testString); # rewind rewind($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.0190.00316.88
8.3.50.0130.01022.02
8.3.40.0140.00018.84
8.3.30.0150.00318.74
8.3.20.0040.00420.29
8.3.10.0040.00423.61
8.3.00.0080.00019.66
8.2.180.0180.00416.75
8.2.170.0030.01722.96
8.2.160.0170.00020.44
8.2.150.0030.00624.18
8.2.140.0060.00324.66
8.2.130.0080.00019.19
8.2.120.0030.00626.35
8.2.110.0040.00420.70
8.2.100.0040.00817.93
8.2.90.0000.00819.27
8.2.80.0030.00617.97
8.2.70.0070.00517.38
8.2.60.0110.00017.80
8.2.50.0040.00418.07
8.2.40.0030.00620.95
8.2.30.0000.00720.72
8.2.20.0040.00417.66
8.2.10.0000.00718.21
8.2.00.0000.00718.07
8.1.280.0150.00625.92
8.1.270.0090.00020.33
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0080.00022.19
8.1.230.0080.00317.66
8.1.220.0000.00817.77
8.1.210.0080.00018.77
8.1.200.0030.00617.35
8.1.190.0060.00317.36
8.1.180.0040.00418.10
8.1.170.0040.00418.71
8.1.160.0080.00020.72
8.1.150.0040.00418.92
8.1.140.0080.00019.48
8.1.130.0070.00017.65
8.1.120.0030.00517.50
8.1.110.0040.00417.46
8.1.100.0040.00417.52
8.1.90.0000.00817.43
8.1.80.0040.00417.52
8.1.70.0000.00717.45
8.1.60.0090.00017.55
8.1.50.0060.00317.61
8.1.40.0090.00017.56
8.1.30.0090.00017.59
8.1.20.0040.00417.56
8.1.10.0040.00417.64
8.1.00.0040.00417.50
8.0.300.0070.00018.77
8.0.290.0070.00016.75
8.0.280.0070.00018.46
8.0.270.0000.00717.36
8.0.260.0030.00317.39
8.0.250.0000.00717.16
8.0.240.0000.00816.98
8.0.230.0030.00317.01
8.0.220.0000.00717.05
8.0.210.0000.00817.10
8.0.200.0030.00317.13
8.0.190.0000.00717.02
8.0.180.0070.00017.09
8.0.170.0000.00817.07
8.0.160.0030.00517.07
8.0.150.0090.00017.00
8.0.140.0040.00416.90
8.0.130.0030.00313.52
8.0.120.0060.00317.05
8.0.110.0030.00517.03
8.0.100.0040.00416.96
8.0.90.0050.00217.07
8.0.80.0090.00617.05
8.0.70.0000.00817.09
8.0.60.0030.00316.88
8.0.50.0000.00816.95
8.0.30.0110.00917.30
8.0.20.0110.01317.40
8.0.10.0040.00417.07
8.0.00.0140.00516.73
7.4.330.0030.00316.79
7.4.320.0000.00716.39
7.4.300.0060.00016.59
7.4.290.0030.00316.50
7.4.280.0070.00416.56
7.4.270.0030.00616.51
7.4.260.0080.00016.50
7.4.250.0000.00716.55
7.4.240.0020.00616.49
7.4.230.0040.00216.64
7.4.220.0110.01116.43
7.4.210.0090.00916.67
7.4.200.0000.00616.28
7.4.160.0060.00916.47
7.4.150.0190.00017.40
7.4.140.0160.00517.86
7.4.130.0140.00616.63
7.4.120.0090.00816.64
7.4.110.0130.00716.75
7.4.100.0060.01116.34
7.4.90.0070.01116.67
7.4.80.0070.01119.39
7.4.70.0060.00916.50
7.4.60.0100.00616.54
7.4.50.0130.00316.55
7.4.40.0150.00616.54
7.4.30.0030.02016.32
7.4.10.0110.00714.81
7.4.00.0120.00214.97
7.3.330.0050.00013.27
7.3.320.0020.00313.19
7.3.310.0000.00716.38
7.3.300.0040.00416.41
7.3.290.0050.01116.41
7.3.280.0050.01116.41
7.3.270.0120.00817.40
7.3.260.0110.00616.48
7.3.250.0070.01116.39
7.3.240.0090.00816.49
7.3.230.0090.01216.49
7.3.210.0090.00916.49
7.3.200.0090.00916.37
7.3.190.0130.00916.20
7.3.180.0030.01716.26
7.3.170.0120.00616.42
7.3.160.0080.00716.55
7.3.130.0100.00614.71
7.3.120.0090.00714.67
7.3.110.0060.00914.67
7.3.100.0060.00714.76
7.3.90.0060.00614.99
7.3.80.0070.00514.94
7.3.70.0070.00714.79
7.3.60.0100.00414.90
7.3.50.0070.00614.74
7.3.40.0070.00614.78
7.3.30.0050.00714.62
7.3.20.0060.00916.63
7.3.10.0050.00916.70
7.3.00.0090.00616.42
7.2.330.0070.01416.46
7.2.320.0110.00616.80
7.2.310.0090.00916.90
7.2.300.0060.01216.82
7.2.290.0130.00416.57
7.2.260.0040.01514.77
7.2.250.0070.01014.81
7.2.240.0050.01114.90
7.2.230.0030.01215.04
7.2.220.0090.00715.29
7.2.210.0080.00515.17
7.2.200.0040.00715.11
7.2.190.0100.00315.00
7.2.180.0110.00215.02
7.2.170.0060.00815.05
7.2.160.0080.00715.02
7.2.150.0050.01116.76
7.2.140.0050.00916.92
7.2.130.0130.00516.86
7.2.120.0020.01116.83
7.2.110.0050.00816.90
7.2.100.0060.00916.79
7.2.90.0040.00816.83
7.2.80.0070.00916.88
7.2.70.0160.00616.93
7.2.60.0030.01016.80
7.2.50.0040.00916.98
7.2.40.0030.00916.90
7.2.30.0040.01016.91
7.2.20.0060.00316.62
7.2.10.0070.01016.95
7.2.00.0030.00917.73
7.1.330.0080.00715.77
7.1.320.0060.00715.78
7.1.310.0060.00515.80
7.1.300.0060.00715.62
7.1.290.0060.00715.63
7.1.280.0050.00615.72
7.1.270.0030.01015.71
7.1.260.0090.00515.63
7.1.250.0100.00515.62
7.1.240.0000.01215.51
7.1.230.0090.00615.54
7.1.220.0090.00315.74
7.1.210.0070.00715.80
7.1.200.0090.00915.73
7.1.190.0030.01015.71
7.1.180.0070.00715.73
7.1.170.0040.00715.82
7.1.160.0080.00815.76
7.1.150.0030.01415.51
7.1.140.0070.00715.82
7.1.130.0070.00715.77
7.1.120.0030.01015.63
7.1.110.0040.00715.88
7.1.100.0060.00616.89
7.1.90.0060.00915.67
7.1.80.0090.00615.66
7.1.70.0050.00516.30
7.1.60.0080.01117.34
7.1.50.0030.01416.28
7.1.40.0000.01415.68
7.1.30.0060.01215.71
7.1.20.0030.00915.90
7.1.10.0090.00315.59
7.1.00.0080.03719.21
7.0.330.0060.01015.32
7.0.320.0040.00415.09
7.0.310.0090.00315.40
7.0.300.0090.00615.24
7.0.290.0090.00315.22
7.0.280.0070.00715.07
7.0.270.0040.01115.27
7.0.260.0040.00815.18
7.0.250.0060.00615.30
7.0.240.0030.00715.57
7.0.230.0030.01315.10
7.0.220.0060.00915.33
7.0.210.0000.01015.08
7.0.200.0040.00716.10
7.0.190.0000.01115.16
7.0.180.0030.01015.45
7.0.170.0060.00315.55
7.0.160.0030.00715.27
7.0.150.0030.00915.20
7.0.140.0040.00415.30
7.0.130.0090.00615.54
7.0.120.0090.00915.35
7.0.110.0080.00415.35
7.0.100.0000.01015.07
7.0.90.0080.00615.51
7.0.80.0070.01115.52
7.0.70.0070.01015.25
7.0.60.0050.02917.68
7.0.50.0020.03516.76
7.0.40.0030.04816.76
7.0.30.0150.02516.82
7.0.20.0200.04216.80
7.0.10.0050.04116.82
7.0.00.0100.02816.78
5.6.400.0070.01114.52
5.6.390.0100.00314.21
5.6.380.0120.00314.25
5.6.370.0000.01414.55
5.6.360.0000.01514.39
5.6.350.0120.00314.04
5.6.340.0030.00614.29
5.6.330.0030.00714.47
5.6.320.0150.00014.43
5.6.310.0100.00314.35
5.6.300.0000.00814.45
5.6.290.0040.00714.54
5.6.280.0030.03817.73
5.6.270.0060.00914.29
5.6.260.0030.00614.52
5.6.250.0000.01214.15
5.6.240.0110.00314.34
5.6.230.0000.01414.63
5.6.220.0030.00614.27
5.6.210.0030.02617.53
5.6.200.0090.03816.24
5.6.190.0050.04017.56
5.6.180.0100.02917.55
5.6.170.0130.02517.43
5.6.160.0120.03817.40
5.6.150.0050.04816.31
5.6.140.0080.03716.28
5.6.130.0110.03516.23
5.6.120.0100.03817.57
5.6.110.0050.04717.75
5.6.100.0000.02617.73
5.6.90.0060.04817.70
5.6.80.0020.03017.29
5.6.70.0030.00714.30
5.6.60.0090.00914.37
5.6.50.0060.00614.32
5.6.40.0070.01114.14
5.6.30.0110.00314.39
5.6.20.0030.01014.54
5.6.10.0030.00914.36
5.6.00.0090.00314.37
5.5.380.0100.00314.31
5.5.370.0090.00614.34
5.5.360.0060.00614.33
5.5.350.0180.03717.43
5.5.340.0100.03216.29
5.5.330.0080.02317.40
5.5.320.0130.02317.24
5.5.310.0160.02017.33
5.5.300.0020.04816.07
5.5.290.0170.04016.08
5.5.280.0070.05017.61
5.5.270.0050.04517.55
5.5.260.0020.03417.58
5.5.250.0050.04017.43
5.5.240.0130.03717.28
5.5.230.0000.01013.97
5.5.220.0030.01014.36
5.5.210.0040.00414.00
5.5.200.0070.00713.84
5.5.190.0000.01514.12
5.5.180.0090.00614.29
5.5.170.0000.01313.98
5.5.160.0030.01314.17
5.5.150.0000.01414.31
5.5.140.0070.00314.28
5.5.130.0090.00614.31
5.5.120.0130.00014.14
5.5.110.0080.00814.18
5.5.100.0080.00814.15
5.5.90.0100.00314.48
5.5.80.0090.00314.09
5.5.70.0080.00414.36
5.5.60.0070.00713.92
5.5.50.0030.01014.11
5.5.40.0060.00914.34
5.5.30.0040.01114.26
5.5.20.0060.00914.48
5.5.10.0060.01213.98
5.5.00.0070.01014.10

preferences:
55.29 ms | 401 KiB | 5 Q