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) { ZLog::Write(LOGLEVEL_DEBUG, "StringStreamWrapper::Open(): len = ".strlen($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; ####################################### $stream = fopen('php://memory','r+'); fwrite($stream, $testString); rewind($stream); stream_filter_append($stream, 'convert.base64-encode'); echo "memoryStream 1 = " . stream_get_contents($stream).PHP_EOL; ####################################### $stream = fopen('php://memory','r+'); fwrite($stream, $testString); rewind($stream); stream_filter_append($stream, 'replacenullchar'); stream_filter_append($stream, 'convert.base64-encode'); echo "memoryStream 2 = " . stream_get_contents($stream).PHP_EOL; ####################################### $stream = StringStreamWrapper::Open($testString); stream_filter_append($stream, 'convert.base64-encode'); echo "StringStreamWrapper 1 = " . stream_get_contents($stream).PHP_EOL; ####################################### $stream = StringStreamWrapper::Open($testString); stream_filter_append($stream, 'replacenullchar'); stream_filter_append($stream, 'convert.base64-encode'); echo "StringStreamWrapper 2 = " . stream_get_contents($stream).PHP_EOL; ####################################### $stream = StringStreamWrapperFixed::Open($testString); stream_filter_append($stream, 'convert.base64-encode'); echo "StringStreamWrapperFixed 1 = " . stream_get_contents($stream).PHP_EOL; ####################################### $stream = StringStreamWrapperFixed::Open($testString); stream_filter_append($stream, 'replacenullchar'); stream_filter_append($stream, 'convert.base64-encode'); echo "StringStreamWrapperFixed 2 = " . stream_get_contents($stream).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.70.0160.00616.75
8.3.60.0110.00417.00
8.3.50.0050.01321.26
8.3.40.0110.00718.88
8.3.30.0120.00318.82
8.3.20.0040.00420.14
8.3.10.0080.00023.52
8.3.00.0080.00019.91
8.2.180.0040.01116.75
8.2.170.0070.01022.96
8.2.160.0030.01020.47
8.2.150.0040.00424.18
8.2.140.0070.00024.66
8.2.130.0030.00520.97
8.2.120.0000.00826.35
8.2.110.0050.00520.92
8.2.100.0070.00418.03
8.2.90.0050.00319.40
8.2.80.0000.00917.97
8.2.70.0050.00317.59
8.2.60.0000.00817.93
8.2.50.0040.00418.07
8.2.40.0000.00821.11
8.2.30.0000.00720.68
8.2.20.0000.00817.75
8.2.10.0040.00418.16
8.2.00.0040.00418.12
8.1.280.0040.01425.92
8.1.270.0080.00823.99
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0060.00323.84
8.1.230.0040.00817.79
8.1.220.0060.00317.74
8.1.210.0030.00618.77
8.1.200.0090.00017.37
8.1.190.0030.00517.25
8.1.180.0030.00518.10
8.1.170.0000.00818.66
8.1.160.0000.00720.93
8.1.150.0040.00418.99
8.1.140.0050.00319.67
8.1.130.0000.00717.75
8.1.120.0040.00417.43
8.1.110.0000.00817.46
8.1.100.0030.00617.59
8.1.90.0040.00417.38
8.1.80.0040.00417.56
8.1.70.0060.00317.36
8.1.60.0000.00817.61
8.1.50.0060.00317.59
8.1.40.0000.00917.54
8.1.30.0000.00917.69
8.1.20.0040.00417.70
8.1.10.0040.00417.50
8.1.00.0030.00517.46
8.0.300.0000.00718.77
8.0.290.0070.00017.00
8.0.280.0000.00718.56
8.0.270.0070.00017.37
8.0.260.0000.00717.48
8.0.250.0030.00317.18
8.0.240.0050.00317.02
8.0.230.0030.00317.15
8.0.220.0050.00316.93
8.0.210.0040.00417.06
8.0.200.0050.00317.13
8.0.190.0040.00417.14
8.0.180.0030.00516.97
8.0.170.0000.00817.11
8.0.160.0000.00816.93
8.0.150.0040.00417.05
8.0.140.0040.00417.00
8.0.130.0000.00613.45
8.0.120.0040.00417.07
8.0.110.0000.00717.01
8.0.100.0040.00417.13
8.0.90.0020.00517.13
8.0.80.0060.01016.99
8.0.70.0050.00316.93
8.0.60.0080.00017.07
8.0.50.0000.00816.98
8.0.30.0130.00517.09
8.0.20.0100.00917.44
8.0.10.0040.00416.98
8.0.00.0090.01116.86
7.4.330.0050.00016.66
7.4.320.0000.00716.54
7.4.300.0000.00616.70
7.4.290.0030.00316.60
7.4.280.0000.00816.56
7.4.270.0030.00616.56
7.4.260.0000.00716.43
7.4.250.0000.00716.62
7.4.240.0020.00516.61
7.4.230.0030.00316.47
7.4.220.0000.00716.65
7.4.210.0040.01116.59
7.4.200.0040.00316.46
7.4.160.0130.00316.64
7.4.150.0160.00317.40
7.4.140.0110.00917.86
7.4.130.0090.00916.70
7.4.120.0060.01116.65
7.4.110.0100.00716.73
7.4.100.0070.01416.43
7.4.90.0110.00816.54
7.4.80.0070.01719.39
7.4.70.0060.01216.74
7.4.60.0070.01016.60
7.4.50.0060.00916.45
7.4.40.0060.00916.46
7.4.30.0090.00916.67
7.4.00.0030.01314.92
7.3.330.0000.00613.56
7.3.320.0000.00713.36
7.3.310.0050.00316.50
7.3.300.0040.00416.59
7.3.290.0090.00716.52
7.3.280.0070.01016.54
7.3.270.0030.01417.40
7.3.260.0180.00316.67
7.3.250.0110.00916.49
7.3.240.0080.00816.52
7.3.230.0080.00816.56
7.3.210.0070.01116.44
7.3.200.0090.00916.40
7.3.190.0060.01016.76
7.3.180.0070.01316.57
7.3.170.0080.00916.71
7.3.160.0090.00916.57
7.3.10.0070.00716.82
7.3.00.0030.00516.63
7.2.330.0110.00616.77
7.2.320.0000.01716.80
7.2.310.0090.00916.75
7.2.300.0090.01316.65
7.2.290.0060.01316.74
7.2.130.0100.00716.95
7.2.120.0030.00917.09
7.2.110.0150.00317.19
7.2.100.0070.00716.75
7.2.90.0070.00716.93
7.2.80.0150.00316.94
7.2.70.0060.00616.61
7.2.60.0100.00516.91
7.2.50.0090.00616.93
7.2.40.0040.01216.44
7.2.30.0000.01516.42
7.2.20.0040.01117.04
7.2.10.0060.00616.89
7.2.00.0070.00618.35
7.1.250.0030.00915.54
7.1.200.0040.01115.69
7.1.100.0000.01218.19
7.1.70.0030.00517.24
7.1.60.0110.01119.13
7.1.50.0000.01017.05
7.1.00.0100.06722.44
7.0.200.0040.00416.48
7.0.100.0130.08020.01
7.0.90.0130.08019.95
7.0.80.0070.08019.89
7.0.70.0130.07319.89
7.0.60.0030.07020.05
7.0.50.0170.06720.32
7.0.40.0070.05320.05
7.0.30.0130.05019.95
7.0.20.0070.07720.10
7.0.10.0030.08319.89
7.0.00.0030.09019.95
5.6.250.0070.08020.77
5.6.240.0170.07320.66
5.6.230.0170.07720.69
5.6.220.0100.07720.62
5.6.210.0070.07320.68
5.6.200.0130.07321.04
5.6.190.0000.06021.05
5.6.180.0100.08021.09
5.6.170.0130.07721.05
5.6.160.0100.08021.11
5.6.150.0200.04720.95
5.6.140.0130.03720.93
5.6.130.0130.08021.02
5.6.120.0070.09020.92
5.6.110.0170.07721.05
5.6.100.0070.07321.07
5.6.90.0000.09321.09
5.6.80.0270.05720.55
5.6.70.0130.06720.40
5.6.60.0130.07320.39
5.6.50.0130.07320.44
5.6.40.0170.07320.40
5.6.30.0100.04720.32
5.6.20.0030.04720.37
5.6.10.0100.04720.52
5.6.00.0130.06320.41
5.5.380.0000.08020.42
5.5.370.0030.04720.39
5.5.360.0070.08020.40
5.5.350.0070.05320.39
5.5.340.0170.07320.76
5.5.330.0130.07020.91
5.5.320.0130.07720.73
5.5.310.0130.07320.84
5.5.300.0200.07020.79
5.5.290.0030.08720.88
5.5.280.0070.08020.92
5.5.270.0130.07320.82
5.5.260.0070.08720.85
5.5.250.0200.06720.59
5.5.240.0200.05320.15
5.5.230.0030.10020.29
5.5.220.0070.08020.01
5.5.210.0130.07720.29
5.5.200.0130.08020.11
5.5.190.0100.07320.14
5.5.180.0030.05019.98
5.5.160.0030.05720.15
5.5.150.0100.07720.18
5.5.140.0100.07720.17
5.5.130.0070.08020.18
5.5.120.0030.08320.23
5.5.110.0070.05020.10
5.5.100.0130.06720.16
5.5.90.0170.04020.01
5.5.80.0070.07720.06
5.5.70.0100.07320.16
5.5.60.0100.06320.09
5.5.50.0170.06720.07
5.5.40.0170.07019.93
5.5.30.0100.07719.95
5.5.20.0100.05020.05
5.5.10.0030.07719.97
5.5.00.0130.07020.03

preferences:
66.55 ms | 401 KiB | 5 Q