3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace KHerGe\File; use Exception; use KHerGe\File\Exception\FileException; use SplFileObject; /** * Manages errors for read and write operations. * * @author Kevin Herrera <kevin@herrera.io> */ class File extends SplFileObject { /** * @override */ public function __construct( $filename, $open_mode = 'r', $use_include_path = false, $context = null ) { try { if (null === $context) { parent::__construct( $filename, $open_mode, $use_include_path ); } else { parent::__construct( $filename, $open_mode, $use_include_path, $context ); } } catch (Exception $exception) { throw FileException::openFailed($filename, $exception); } } /** * Creates a new file object. * * @param string $filename The path to the file. * @param string $open_mode The file open mode. * @param boolean $use_include_path Use the include path? * @param resource $context A valid context resource. * * @return $this The new file object. */ public static function create( $filename, $open_mode = 'r', $use_include_path = false, $context = null ) { return new static($filename, $open_mode, $use_include_path, $context); } /** * Creates a new temporary file and returns its file object. * * @param string $prefix The prefix for the name of the temporary file. (default: php-) * @param string $mode The file open mode. (default: w+) * * @return $this The new file object. * * @throws FileException If the temporary file could not be created. */ public static function createTemp($prefix = 'php-', $mode = 'w+') { return new static(static::createTempPath($prefix), $mode); } /** * Creates a new, named temporary file and returns its file object. * * @param string $name The name of the temporary file. * @param string $mode The file open mode. (default: w+) * * @return $this The new file object. */ public static function createTempNamed($name, $mode = 'w+') { return new static(static::createTempPathNamed($name), $mode); } /** * Creates a new temporary file and returns its path. * * @param string $prefix The prefix for the name of the temporary file. * * @return string The path to the temporary file. * * @throws FileException If the temporary file could not be created. */ public static function createTempPath($prefix = 'php-') { $temp = tempnam(sys_get_temp_dir(), $prefix); if (false === $temp) { // @codeCoverageIgnoreStart throw new FileException( 'A new temporary file could not be created.' ); } // @codeCoverageIgnoreEnd return $temp; } /** * Creates a new, named temporary file and returns its path. * * @param string $name The name for the temporary file. * * @return string The path to the temporary file. * * @throws FileException If the temporary file could not be created. */ public static function createTempPathNamed($name) { $dir = static::createTempPath(); if (!unlink($dir)) { // @codeCoverageIgnoreStart throw new FileException( 'The temporary file could not be deleted.' ); } // @codeCoverageIgnoreEnd if (!mkdir($dir)) { // @codeCoverageIgnoreStart throw new FileException( 'A new temporary directory could not be created.' ); } // @codeCoverageIgnoreEnd $path = $dir . DIRECTORY_SEPARATOR . $name; if (!touch($path)) { // @codeCoverageIgnoreStart throw new FileException( 'A new temporary file could not be created.' ); } // @codeCoverageIgnoreEnd return $path; } /** * @override */ public function fflush() { if (!parent::fflush()) { throw FileException::flushFailed($this); } return true; } /** * @override */ public function fgetc() { if (false === ($c = parent::fgetc())) { throw FileException::reachedEOF($this); } return $c; } /** * @override */ public function fgetcsv( $delimiter = ',', $enclosure = '"', $escape = '\\' ) { if (!is_array($row = parent::fgetcsv($delimiter, $enclosure, $escape))) { throw FileException::readFailed($this); } return $row; } /** * @override */ public function fgets() { try { if (false === ($string = parent::fgets())) { throw FileException::readFailed($this); } } catch (Exception $exception) { throw FileException::readFailed($this, $exception); } return $string; } /** * @override */ public function fgetss($allowable_tags = null) { if (false === ($string = parent::fgetss($allowable_tags))) { throw FileException::readFailed($this); } return $string; } /** * @override */ public function flock($operation, &$wouldblock = null) { if (!parent::flock($operation, $wouldblock)) { throw FileException::lockFailed($this); } return true; } /** * @override */ public function fputcsv( $fields, $delimiter = ',', $enclosure = '"', $escape = '\\' ) { if (false === ($length = parent::fputcsv($fields, $delimiter, $enclosure, $escape))) { throw FileException::writeFailed($this); } return $length; } /** * @override */ public function fseek($offset, $whence = SEEK_SET) { if (-1 === parent::fseek($offset, $whence)) { throw FileException::seekFailed($this); } return 0; } /** * @override */ public function ftell() { if (false === ($position = parent::ftell())) { throw FileException::tellFailed($this); } return $position; } /** * @override */ public function ftruncate($size) { if (!parent::ftruncate($size)) { throw FileException::truncateFailed($this); } return true; } /** * @override */ public function fwrite($str, $length = null) { if (null === $length) { $length = strlen($str); } if (null === ($bytes = parent::fwrite($str, $length))) { throw FileException::writeFailed($this); } return $bytes; } /** * @override */ public function seek($line_pos) { try { parent::seek($line_pos); } catch (Exception $exception) { throw FileException::seekFailed($this, $exception); } } }

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.0120.00917.00
8.3.50.0170.00521.18
8.3.40.0090.00618.93
8.3.30.0070.01018.95
8.3.20.0080.00020.41
8.3.10.0040.00421.90
8.3.00.0080.00017.38
8.2.180.0110.00418.41
8.2.170.0070.00718.82
8.2.160.0070.00722.96
8.2.150.0030.00524.18
8.2.140.0000.00824.66
8.2.130.0030.00626.16
8.2.120.0060.00319.23
8.2.110.0060.00319.44
8.2.100.0110.00017.93
8.2.90.0040.00419.17
8.2.80.0030.00517.97
8.2.70.0030.00517.50
8.2.60.0030.00617.80
8.2.50.0060.00618.09
8.2.40.0030.00620.71
8.2.30.0000.00718.06
8.2.20.0000.00917.76
8.2.10.0040.00417.95
8.2.00.0050.00517.75
8.1.280.0100.01025.92
8.1.270.0030.00520.45
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0080.00322.75
8.1.230.0090.00317.77
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0040.00417.36
8.1.190.0060.00317.22
8.1.180.0040.00418.10
8.1.170.0000.00818.66
8.1.160.0000.00820.75
8.1.150.0040.00418.88
8.1.140.0060.00317.35
8.1.130.0030.00317.86
8.1.120.0050.00317.34
8.1.110.0060.00317.37
8.1.100.0050.00217.35
8.1.90.0080.00017.48
8.1.80.0020.00517.50
8.1.70.0030.00317.48
8.1.60.0040.00417.58
8.1.50.0040.00417.48
8.1.40.0000.00917.55
8.1.30.0040.00417.54
8.1.20.0040.00417.54
8.1.10.0050.00317.52
8.1.00.0000.00917.43
8.0.300.0080.00018.77
8.0.290.0070.00016.75
8.0.280.0070.00018.41
8.0.270.0000.00717.24
8.0.260.0000.00717.25
8.0.250.0040.00416.82
8.0.240.0000.00816.92
8.0.230.0050.00316.89
8.0.220.0030.00316.79
8.0.210.0040.00416.91
8.0.200.0030.00316.91
8.0.190.0050.00316.97
8.0.180.0040.00416.80
8.0.170.0090.00016.87
8.0.160.0040.00416.81
8.0.150.0000.00716.94
8.0.140.0080.00016.89
8.0.130.0000.00813.34
8.0.120.0040.00416.82
8.0.110.0040.00416.94
8.0.100.0080.00016.75
8.0.90.0050.00516.87
8.0.80.0070.01016.80
8.0.70.0040.00416.98
8.0.60.0040.00416.74
8.0.50.0050.00316.87
8.0.30.0150.00516.95
8.0.20.0130.00617.40
8.0.10.0040.00417.06
8.0.00.0080.01216.73
7.4.330.0050.00015.03
7.4.320.0000.00616.56
7.4.300.0000.00616.45
7.4.290.0030.00316.55
7.4.280.0060.00316.61
7.4.270.0030.00316.36
7.4.260.0030.00516.45
7.4.250.0000.00816.46
7.4.240.0030.00316.54
7.4.230.0000.00716.66
7.4.220.0060.01216.49
7.4.210.0070.00716.52
7.4.200.0000.00716.51
7.4.160.0090.00916.52
7.4.150.0110.00617.40
7.4.140.0120.00517.86
7.4.130.0110.01216.45
7.4.120.0060.01116.62
7.4.110.0210.00316.71
7.4.100.0090.00916.44
7.4.90.0150.00316.32
7.4.80.0060.01219.39
7.4.70.0060.01216.36
7.4.60.0100.00616.54
7.4.50.0060.00316.62
7.4.40.0210.00316.39
7.4.30.0110.00716.48
7.4.10.0100.00714.91
7.4.00.0070.00914.83
7.3.330.0030.00313.29
7.3.320.0150.00313.16
7.3.310.0000.00716.18
7.3.300.0050.00316.29
7.3.290.0090.00716.25
7.3.280.0080.00916.31
7.3.270.0140.00417.40
7.3.260.0150.00916.40
7.3.250.0120.00916.31
7.3.240.0100.00616.27
7.3.230.0100.01316.42
7.3.210.0100.01316.57
7.3.200.0100.01319.39
7.3.190.0100.00916.41
7.3.180.0120.00616.34
7.3.170.0110.01116.38
7.3.160.0120.00616.18
7.3.130.0110.00614.73
7.3.120.0040.01414.72
7.3.110.0040.01514.58
7.3.100.0110.00314.91
7.3.90.0020.01414.78
7.3.80.0050.00914.61
7.3.70.0070.01014.82
7.3.60.0070.00714.66
7.3.50.0060.00614.82
7.3.40.0060.00514.75
7.3.30.0030.01114.78
7.3.20.0070.00816.47
7.3.10.0050.00816.50
7.3.00.0050.00616.51
7.2.330.0100.00716.29
7.2.320.0120.00816.60
7.2.310.0150.00316.58
7.2.300.0040.01316.44
7.2.290.0040.01316.58
7.2.260.0120.00614.78
7.2.250.0040.01314.94
7.2.240.0080.00915.08
7.2.230.0030.00814.95
7.2.220.0070.00714.79
7.2.210.0050.00714.87
7.2.200.0040.01014.88
7.2.190.0100.00514.80
7.2.180.0030.00814.96
7.2.170.0030.01314.83
7.2.160.0060.00714.88
7.2.150.0110.00416.59
7.2.140.0100.00716.70
7.2.130.0070.01116.84
7.2.120.0030.01216.52
7.2.110.0140.00716.65
7.2.100.0030.00616.72
7.2.90.0080.00316.63
7.2.80.0060.00916.70
7.2.70.0100.00316.91
7.2.60.0110.00216.62
7.2.50.0060.01216.69
7.2.40.0090.00616.70
7.2.30.0030.00716.73
7.2.20.0060.00916.87
7.2.10.0090.00316.89
7.2.00.0110.01017.97
7.1.330.0080.00515.68
7.1.320.0080.00715.71
7.1.310.0080.00515.63
7.1.300.0030.00815.37
7.1.290.0060.00415.62
7.1.280.0050.00915.47
7.1.270.0050.00915.66
7.1.260.0040.01015.43
7.1.250.0070.00715.62
7.1.240.0080.00415.50
7.1.230.0110.00415.68
7.1.220.0070.00715.59
7.1.210.0030.01015.50
7.1.200.0050.00715.57
7.1.190.0100.00315.64
7.1.180.0090.00315.66
7.1.170.0070.00715.55
7.1.160.0040.00715.69
7.1.150.0100.00315.55
7.1.140.0060.00615.51
7.1.130.0060.00615.59
7.1.120.0070.00315.52
7.1.110.0000.01215.67
7.1.100.0070.00616.70
7.1.90.0030.01715.75
7.1.80.0070.00715.66
7.1.70.0060.00616.24
7.1.60.0090.00817.54
7.1.50.0180.00525.23
7.1.40.0150.00015.63
7.1.30.0040.00715.66
7.1.20.0030.00615.50
7.1.10.0090.00615.75
7.1.00.0080.03819.06
7.0.330.0030.01315.02
7.0.320.0060.00615.42
7.0.310.0100.00315.24
7.0.300.0080.00415.05
7.0.290.0000.01515.22
7.0.280.0060.00315.27
7.0.270.0030.01115.42
7.0.260.0000.01315.18
7.0.250.0030.01015.27
7.0.240.0060.01215.11
7.0.230.0080.01115.44
7.0.220.0080.00415.39
7.0.210.0030.01015.29
7.0.200.0010.01016.04
7.0.190.0000.01315.32
7.0.180.0000.01215.10
7.0.170.0120.00415.35
7.0.160.0030.01015.04
7.0.150.0120.00315.41
7.0.140.0020.03318.54
7.0.130.0040.00415.21
7.0.120.0070.00415.20
7.0.110.0100.00015.35
7.0.100.0130.04017.52
7.0.90.0130.02517.55
7.0.80.0080.03817.78
7.0.70.0110.03117.68
7.0.60.0130.03517.75
7.0.50.0100.02217.89
7.0.40.0050.04016.74
7.0.30.0100.02616.70
7.0.20.0080.03516.70
7.0.10.0100.02716.70
7.0.00.0120.03816.75
5.6.400.0090.00914.62
5.6.390.0060.01014.18
5.6.380.0060.00914.44
5.6.370.0060.00913.83
5.6.360.0070.00714.06
5.6.350.0040.01114.49
5.6.340.0060.01214.21
5.6.330.0090.00314.32
5.6.320.0130.00314.30
5.6.310.0100.00014.11
5.6.300.0070.00714.07
5.6.290.0090.00614.19
5.6.280.0000.01014.13
5.6.270.0060.00614.31
5.6.260.0070.01014.13
5.6.250.0030.03817.52
5.6.240.0050.03217.38
5.6.230.0020.02617.35
5.6.220.0070.04317.54
5.6.210.0150.04117.47
5.6.200.0080.04517.53
5.6.190.0070.03517.60
5.6.180.0100.04217.65
5.6.170.0110.04517.66
5.6.160.0070.03017.81
5.6.150.0080.04217.52
5.6.140.0100.04117.59
5.6.130.0050.04017.56
5.6.120.0050.03017.57
5.6.110.0030.03217.65
5.6.100.0020.02917.59
5.6.90.0050.02717.67
5.6.80.0020.02617.47
5.6.70.0050.02017.25
5.6.60.0050.02717.41
5.6.50.0050.03817.21
5.6.40.0020.04317.26
5.6.30.0020.02317.42
5.6.20.0060.02317.31
5.6.10.0080.02017.20
5.6.00.0050.04017.19
5.5.380.0070.04717.34
5.5.370.0030.04217.36
5.5.360.0080.02617.33
5.5.350.0050.04417.32
5.5.340.0120.03317.50
5.5.330.0100.04217.44
5.5.320.0140.03517.46
5.5.310.0030.03117.62
5.5.300.0100.02217.63
5.5.290.0100.02717.36
5.5.280.0120.03517.58
5.5.270.0140.02017.65
5.5.260.0080.02517.64
5.5.250.0030.02517.34
5.5.240.0070.02017.19
5.5.230.0060.02417.10
5.5.220.0040.02517.10
5.5.210.0060.02517.13
5.5.200.0100.03517.18
5.5.190.0070.03817.23
5.5.180.0040.02617.09
5.5.170.0040.01414.21
5.5.160.0050.03017.14
5.5.150.0030.02217.14
5.5.140.0160.01817.21
5.5.130.0060.02517.21
5.5.120.0050.02017.32
5.5.110.0020.02816.94
5.5.100.0000.03217.13
5.5.90.0000.02717.17
5.5.80.0050.02517.03
5.5.70.0060.03417.12
5.5.60.0050.02317.04
5.5.50.0070.02217.08
5.5.40.0010.02717.03
5.5.30.0050.02317.10
5.5.20.0050.02217.06
5.5.10.0100.02017.08
5.5.00.0050.02617.20
5.4.450.0070.03815.16
5.4.440.0030.03614.96
5.4.430.0030.03215.23
5.4.420.0030.02815.10
5.4.410.0030.02815.11
5.4.400.0030.02014.90
5.4.390.0050.03214.94
5.4.380.0030.02315.04
5.4.370.0070.01814.98
5.4.360.0000.02514.83
5.4.350.0020.02215.11
5.4.340.0070.04214.69
5.4.330.0000.01111.07
5.4.320.0030.02314.96
5.4.310.0030.02515.03
5.4.300.0030.02214.88
5.4.290.0070.02214.90
5.4.280.0020.02414.97
5.4.270.0030.02214.82
5.4.260.0060.01714.81
5.4.250.0020.02314.98
5.4.240.0000.02314.98
5.4.230.0030.02314.80
5.4.220.0060.02314.94
5.4.210.0020.02514.93
5.4.200.0040.02014.96
5.4.190.0050.02014.87
5.4.180.0080.01815.03
5.4.170.0060.02215.01
5.4.160.0050.03514.86
5.4.150.0030.02314.93
5.4.140.0050.01913.48
5.4.130.0050.02913.65
5.4.120.0060.01813.73
5.4.110.0050.03213.70
5.4.100.0020.02413.66
5.4.90.0030.02313.56
5.4.80.0030.02213.71
5.4.70.0040.01913.58
5.4.60.0070.01913.75
5.4.50.0050.02213.66
5.4.40.0030.02113.62
5.4.30.0070.01813.68
5.4.20.0050.01913.63
5.4.10.0080.01813.63
5.4.00.0040.02113.38

preferences:
53.77 ms | 401 KiB | 5 Q