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); # get the output stream (as z-push does) $output = fopen("php://output", "w+"); # attach write filter to output $filter = stream_filter_append($output, 'convert.base64-encode'); echo "outputstream = "; # write to output $written = stream_copy_to_stream($stringstream, $output); flush($output); echo PHP_EOL."Sent $written bytes to 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.70.0110.00418.36
8.3.60.0150.00717.00
8.3.50.0140.00722.10
8.3.40.0060.00918.83
8.3.30.0040.01118.97
8.3.20.0040.00420.16
8.3.10.0040.00423.48
8.3.00.0030.00619.85
8.2.180.0120.00616.63
8.2.170.0000.01422.96
8.2.160.0120.00320.39
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00419.32
8.2.120.0040.00426.35
8.2.110.0060.00320.38
8.2.100.0040.00818.03
8.2.90.0030.00519.36
8.2.80.0050.00317.97
8.2.70.0000.01117.63
8.2.60.0130.00018.03
8.2.50.0030.00518.07
8.2.40.0080.00021.04
8.2.30.0040.00420.72
8.2.20.0000.00917.84
8.2.10.0060.00318.15
8.2.00.0000.00718.03
8.1.280.0070.01125.92
8.1.270.0050.00320.37
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0030.00622.14
8.1.230.0090.00317.65
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0060.00317.38
8.1.190.0040.00417.38
8.1.180.0050.00318.10
8.1.170.0000.00818.46
8.1.160.0000.00820.85
8.1.150.0040.00418.84
8.1.140.0080.00019.61
8.1.130.0030.00317.79
8.1.120.0070.00017.39
8.1.110.0000.00717.55
8.1.100.0040.00417.50
8.1.90.0050.00217.55
8.1.80.0060.00317.39
8.1.70.0000.00717.44
8.1.60.0000.00817.64
8.1.50.0030.00617.49
8.1.40.0000.00817.60
8.1.30.0030.00617.68
8.1.20.0060.00317.71
8.1.10.0000.00817.49
8.1.00.0050.00317.56
8.0.300.0060.00318.77
8.0.290.0050.00216.88
8.0.280.0000.00718.54
8.0.270.0040.00417.28
8.0.260.0030.00317.34
8.0.250.0030.00317.08
8.0.240.0070.00017.12
8.0.230.0000.00717.10
8.0.220.0030.00516.98
8.0.210.0000.00817.07
8.0.200.0000.00716.98
8.0.190.0030.00517.02
8.0.180.0000.00717.14
8.0.170.0040.00416.97
8.0.160.0030.00617.03
8.0.150.0030.00917.06
8.0.140.0000.00716.98
8.0.130.0000.00613.44
8.0.120.0060.00316.92
8.0.110.0040.00417.07
8.0.100.0020.00517.01
8.0.90.0040.00417.08
8.0.80.0060.01017.00
8.0.70.0030.00517.04
8.0.60.0000.00716.85
8.0.50.0040.00417.07
8.0.30.0100.00817.25
8.0.20.0090.01117.40
8.0.10.0050.00317.00
8.0.00.0130.01016.93
7.4.330.0000.00516.77
7.4.320.0000.00716.65
7.4.300.0030.00316.66
7.4.290.0030.00316.61
7.4.280.0030.00816.68
7.4.270.0030.00716.62
7.4.260.0100.00016.57
7.4.250.0000.00716.41
7.4.240.0020.00516.45
7.4.230.0030.00316.71
7.4.220.0120.00916.67
7.4.210.0000.01416.49
7.4.200.0040.00416.36
7.4.160.0090.00616.57
7.4.150.0090.00917.40
7.4.140.0050.01517.86
7.4.130.0110.00816.55
7.4.120.0090.01016.53
7.4.110.0110.00716.70
7.4.100.0030.01516.50
7.4.90.0110.00716.59
7.4.80.0140.00319.39
7.4.70.0030.01316.43
7.4.60.0030.01316.47
7.4.50.0040.01516.51
7.4.40.0100.00716.40
7.4.30.0060.01116.44
7.4.00.0110.00414.98
7.3.330.0030.00313.47
7.3.320.0050.00013.49
7.3.310.0070.00016.36
7.3.300.0000.00716.55
7.3.290.0080.00816.54
7.3.280.0090.00716.51
7.3.270.0140.00317.40
7.3.260.0140.00516.47
7.3.250.0090.00916.54
7.3.240.0060.01316.61
7.3.230.0030.02016.44
7.3.210.0060.01216.58
7.3.200.0100.00716.50
7.3.190.0060.01116.46
7.3.180.0080.00816.29
7.3.170.0060.01516.48
7.3.160.0140.00316.57
7.3.10.0040.01216.37
7.3.00.0030.00916.50
7.2.330.0060.01216.71
7.2.320.0060.01216.43
7.2.310.0130.00616.66
7.2.300.0080.00816.80
7.2.290.0120.00616.89
7.2.130.0050.01016.64
7.2.120.0030.01016.93
7.2.110.0050.00716.72
7.2.100.0080.00716.69
7.2.90.0110.00416.76
7.2.80.0090.00716.83
7.2.70.0040.01116.98
7.2.60.0010.01116.94
7.2.50.0020.00916.78
7.2.40.0050.01016.91
7.2.30.0100.00517.01
7.2.20.0110.00416.96
7.2.10.0110.00816.85
7.2.00.0080.00717.72
7.1.250.0130.01315.68
7.1.230.0070.00315.86
7.1.220.0040.01215.73
7.1.210.0040.01115.83
7.1.200.0050.00715.95
7.1.190.0040.00815.80
7.1.180.0090.00015.86
7.1.170.0100.00315.67
7.1.160.0070.00415.78
7.1.150.0070.00315.92
7.1.140.0030.00715.82
7.1.130.0030.00615.69
7.1.120.0030.01015.95
7.1.110.0120.00315.73
7.1.100.0040.00717.24
7.1.90.0040.00715.61
7.1.80.0080.00315.92
7.1.70.0030.00816.45
7.1.60.0070.01217.58
7.1.50.0070.01316.15
7.1.40.0040.01115.59
7.1.30.8240.00715.87
7.1.20.0030.00915.92
7.1.10.0070.00715.94
7.1.00.0090.03919.15
7.0.310.0030.01315.24
7.0.300.0000.00915.21
7.0.290.0060.00315.35
7.0.280.0060.00615.36
7.0.270.0000.01215.59
7.0.260.0000.01015.18
7.0.250.0060.00315.45
7.0.240.0030.00515.23
7.0.230.0040.00715.29
7.0.220.0080.00415.46
7.0.210.0000.01015.27
7.0.200.0050.00516.03
7.0.190.0000.01015.41
7.0.180.0100.00315.61
7.0.170.0030.00915.44
7.0.160.0000.00815.36
7.0.150.0040.01115.39
7.0.140.0030.01015.33
7.0.130.0150.00015.36
7.0.120.0120.00415.55
7.0.110.0080.00615.15
7.0.100.0180.00215.34
7.0.90.0070.01115.54
7.0.80.0060.01215.65
7.0.70.0080.01115.62
7.0.60.0070.02517.76
7.0.50.0110.02316.71
7.0.40.0090.02916.69
7.0.30.0210.02616.80
7.0.20.0210.02816.82
7.0.10.0060.02516.71
7.0.00.0100.04816.79
5.6.380.0040.01114.72
5.6.370.0060.00614.46
5.6.360.0120.00314.70
5.6.350.0110.00614.57
5.6.340.0140.00314.45
5.6.330.0100.00614.75
5.6.320.0090.00314.79
5.6.310.0050.00814.50
5.6.300.0120.00014.36
5.6.290.0080.00814.66
5.6.280.0060.02417.81
5.6.270.0040.01214.79
5.6.260.0120.00814.45
5.6.250.0150.00514.61
5.6.240.0100.00714.70
5.6.230.0100.01014.61
5.6.220.0090.00614.56
5.6.210.0080.03017.57
5.6.200.0090.03916.43
5.6.190.0100.02817.55
5.6.180.0140.02217.46
5.6.170.0190.02917.63
5.6.160.0020.03317.58
5.6.150.0130.04016.39
5.6.140.0080.03816.33
5.6.130.0100.04016.31
5.6.120.0030.05117.86
5.6.110.0110.04417.80
5.6.100.0060.02217.70
5.6.90.0090.03417.76
5.6.80.0090.02117.44
5.6.70.0090.00614.30
5.6.60.0070.00814.42
5.6.50.0130.00314.31
5.6.40.0050.00814.46
5.6.30.0130.00314.20
5.6.20.0090.00514.32
5.6.10.0080.00514.20
5.6.00.0100.00714.56
5.5.380.0000.01011.33
5.5.370.0000.01111.41
5.5.360.0100.00411.48
5.5.350.0180.04115.88
5.5.340.0080.04314.63
5.5.330.0050.04815.93
5.5.320.0130.02215.75
5.5.310.0130.02615.87
5.5.300.0050.03814.62
5.5.290.0110.03814.78
5.5.280.0100.03616.23
5.5.270.0070.04316.09
5.5.260.0040.02416.13
5.5.250.0150.03815.83
5.5.240.0170.03215.86
5.5.230.0110.00311.14
5.5.220.0110.00311.18
5.5.210.0050.00511.29
5.5.200.0100.00511.36
5.5.190.0080.00411.49
5.5.180.0060.00311.40
5.5.170.0050.01214.45
5.5.160.0130.00011.09
5.5.150.0090.00511.21
5.5.140.0070.00711.42
5.5.130.0130.00011.48
5.5.120.0100.00311.25
5.5.110.0060.00611.30
5.5.100.0090.00311.29
5.5.90.0070.00711.38
5.5.80.0090.00411.38
5.5.70.0110.00411.22
5.5.60.0110.00311.21
5.5.50.0080.00411.16
5.5.40.0030.00711.16
5.5.30.0030.00611.39
5.5.20.0130.00011.45
5.5.10.0070.00411.45
5.5.00.0110.00010.89

preferences:
54.88 ms | 401 KiB | 5 Q