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://temp','r+'); $output = StringStreamWrapper::Open(""); # 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, "test"); # 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.0220.00016.49
8.3.50.0120.00318.18
8.3.40.0120.00319.02
8.3.30.0000.01418.79
8.3.20.0040.00420.38
8.3.10.0040.00423.41
8.3.00.0030.00519.98
8.2.180.0120.00618.54
8.2.170.0070.00722.96
8.2.160.0090.00920.16
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00019.27
8.2.120.0080.00026.35
8.2.110.0030.00719.30
8.2.100.0040.00818.03
8.2.90.0000.00820.42
8.2.80.0040.00417.97
8.2.70.0040.00417.93
8.2.60.0040.00418.22
8.2.50.0060.00318.10
8.2.40.0040.00419.34
8.2.30.0000.00820.66
8.2.20.0080.00017.90
8.2.10.0000.00818.04
8.2.00.0050.00318.11
8.1.280.0030.01725.92
8.1.270.0030.00520.20
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0050.00522.54
8.1.230.0060.00621.05
8.1.220.0040.00417.74
8.1.210.0030.00618.77
8.1.200.0030.00617.35
8.1.190.0040.00417.23
8.1.180.0040.00718.10
8.1.170.0080.00018.60
8.1.160.0050.00220.80
8.1.150.0040.00418.98
8.1.140.0050.00319.61
8.1.130.0000.00717.73
8.1.120.0000.00717.49
8.1.110.0020.00517.50
8.1.100.0040.00417.40
8.1.90.0000.00717.50
8.1.80.0000.00717.39
8.1.70.0030.00317.46
8.1.60.0040.00417.62
8.1.50.0080.00017.56
8.1.40.0030.00517.45
8.1.30.0030.00517.61
8.1.20.0030.00517.52
8.1.10.0000.00817.66
8.1.00.0050.00317.55
8.0.300.0000.00720.17
8.0.290.0030.00617.00
8.0.280.0030.00318.55
8.0.270.0000.00817.40
8.0.260.0070.00017.29
8.0.250.0080.00017.18
8.0.240.0000.00717.08
8.0.230.0040.00317.13
8.0.220.0000.00717.06
8.0.210.0000.00817.00
8.0.200.0060.00017.15
8.0.190.0000.00817.01
8.0.180.0040.00417.07
8.0.170.0040.00416.99
8.0.160.0050.00517.05
8.0.150.0000.00817.05
8.0.140.0000.00716.99
8.0.130.0030.00613.52
8.0.120.0000.00816.88
8.0.110.0040.00416.97
8.0.100.0060.00317.12
8.0.90.0000.00816.95
8.0.80.0070.01017.07
8.0.70.0050.00217.11
8.0.60.0000.00716.92
8.0.50.0040.00416.94
8.0.30.0110.00817.07
8.0.20.0090.00917.40
8.0.10.0000.00817.16
8.0.00.0100.01116.81
7.4.330.0020.00216.84
7.4.320.0070.00016.70
7.4.300.0030.00316.67
7.4.290.0070.00016.53
7.4.280.0000.01016.55
7.4.270.0040.00416.61
7.4.260.0080.00016.52
7.4.250.0050.00216.63
7.4.240.0020.00616.55
7.4.230.0040.00416.75
7.4.220.0150.01016.49
7.4.210.0080.00816.59
7.4.200.0080.00016.64
7.4.160.0070.01316.66
7.4.150.0070.01017.40
7.4.140.0140.01117.86
7.4.130.0130.00516.58
7.4.120.0070.01216.51
7.4.110.0140.00716.43
7.4.100.0070.01116.50
7.4.90.0090.00916.59
7.4.80.0090.00919.39
7.4.70.0030.01416.52
7.4.60.0060.01016.44
7.4.50.0090.00916.48
7.4.40.0090.00916.72
7.4.30.0110.00816.58
7.4.00.0070.00815.06
7.3.330.0000.00613.30
7.3.320.0000.00513.50
7.3.310.0000.00716.63
7.3.300.0000.00716.54
7.3.290.0060.00916.50
7.3.280.0070.01116.53
7.3.270.0120.00917.40
7.3.260.0110.00716.51
7.3.250.0110.00716.49
7.3.240.0110.00916.52
7.3.230.0030.01916.49
7.3.210.0080.00816.43
7.3.200.0030.01516.42
7.3.190.0140.00816.58
7.3.180.0160.00816.61
7.3.170.0100.01016.54
7.3.160.0060.00916.49
7.3.120.0040.01114.91
7.3.110.0070.01014.89
7.3.100.0130.00314.71
7.3.90.0060.00915.14
7.3.80.0140.00014.74
7.3.70.0070.00714.80
7.3.60.0140.00414.76
7.3.50.0000.01515.00
7.3.40.0030.01015.02
7.3.30.0070.01015.00
7.3.20.0090.00016.59
7.3.10.0060.00816.73
7.3.00.0050.00816.72
7.2.330.0070.01116.82
7.2.320.0000.01916.65
7.2.310.0170.00016.65
7.2.300.0000.01816.70
7.2.290.0120.00916.99
7.2.250.0070.01115.04
7.2.240.0100.00615.32
7.2.230.0000.01515.25
7.2.220.0030.00915.16
7.2.210.0110.00415.45
7.2.200.0030.00915.30
7.2.190.0060.00615.25
7.2.180.0120.00315.04
7.2.170.0030.00615.25
7.2.130.0110.00417.02
7.2.120.0000.00916.82
7.2.110.0000.01416.76
7.2.100.0090.00616.94
7.2.90.0060.00616.86
7.2.80.0040.00716.82
7.2.70.0100.00017.11
7.2.60.0100.00516.98
7.2.50.0030.00616.73
7.2.40.0060.00916.71
7.2.30.0080.00616.80
7.2.20.0040.00716.93
7.2.10.0000.01617.03
7.2.00.0080.00718.34
7.1.330.0030.01016.05
7.1.320.0000.01215.89
7.1.310.0000.00916.04
7.1.300.0060.00315.55
7.1.290.0070.00715.86
7.1.280.0060.01215.95
7.1.270.0070.00715.90
7.1.260.0070.00715.66
7.1.250.0050.00515.91
7.1.200.0060.00615.87
7.1.100.0000.01218.34
7.1.70.0030.01317.14
7.1.60.0100.01319.13
7.1.50.0040.01917.01
7.1.00.0070.07322.44
7.0.200.0000.00716.95
7.0.60.0070.08020.14
7.0.50.0030.08718.05
7.0.40.0130.04320.13
7.0.30.0170.05020.33
7.0.20.0370.07020.37
7.0.10.0000.05720.10
7.0.00.0070.04720.09
5.6.280.0030.03321.11
5.6.210.0070.03720.65
5.6.200.0000.05018.29
5.6.190.0070.08720.57
5.6.180.0170.04020.46
5.6.170.0130.05320.51
5.6.160.0070.05320.55
5.6.150.0030.08318.23
5.6.140.0030.04018.28
5.6.130.0030.07018.26
5.6.120.0030.04721.15
5.6.110.0100.08021.02
5.6.100.0030.04021.02
5.6.90.0100.08321.07
5.6.80.0100.07720.54
5.5.350.0200.08020.37
5.5.340.0070.04717.99
5.5.330.0100.04720.32
5.5.320.0170.04020.31
5.5.310.0070.05020.29
5.5.300.0130.07018.08
5.5.290.0030.05318.08
5.5.280.0100.07320.80
5.5.270.0070.08720.91
5.5.260.0030.04320.68
5.5.250.0070.08720.68
5.5.240.0170.07720.20

preferences:
42.93 ms | 400 KiB | 5 Q