3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace TorrentPHP; /** * Interface ClientAdaptor * * If you want to add support for your own torrent client of choice, you need to create an ClientAdaptor that sends * commands to your client. For transmission and vuze, these are RPC calls over the HTTP protocol, but your client may * require command-line calls, for example. * * @package TorrentPHP */ interface ClientAdaptor { /** * Add a torrent to the client * * Each client may have different requirements to add a torrent, so an array of arguments with the key being the * argument name and the value being the argument value is required. It is therefore the specific implementation's * responsibility to provide validation throughout it's usage. * * @param array $arguments A single dimensional array of key value pairs * * @throws ClientException When the client does not return expected output to say that this action succeeded * * @return Torrent The newly added torrent object */ public function addTorrent(array $arguments); /** * Start a torrent * * @param Torrent $torrent * * @throws ClientException When the client does not return expected output to say that this action succeeded * * @return Torrent The newly started torrent object */ public function startTorrent(Torrent $torrent); /** * Pause a torrent * * @param Torrent $torrent * * @throws ClientException When the client does not return expected output to say that this action succeeded * * @return Torrent The newly paused torrent object */ public function pauseTorrent(Torrent $torrent); /** * Delete a torrent - be aware this relates to deleting the torrent file and all files associated with it * * @param Torrent $torrent * * @throws ClientException When the client does not return expected output to say that this action succeeded * * @return void */ public function deleteTorrent(Torrent $torrent); } /** * Class Torrent * * Represents the final torrent object provided by TorrentPHP * * @package TorrentPHP */ class Torrent { /** * Default status */ const STATUS_UNKNOWN = -1; /** * A torrent client error has occurred */ const STATUS_ERROR = 0; /** * Torrent is downloading */ const STATUS_DOWNLOADING = 1; /** * Torrent is paused */ const STATUS_PAUSED = 2; /** * Torrent is seeding */ const STATUS_SEEDING = 3; /** * Torrent has completed both downloading and seeding */ const STATUS_COMPLETE = 4; /** * @var array An array of status matching the status constants for validation */ private $statuses = array( self::STATUS_UNKNOWN => 'unknown', self::STATUS_ERROR => 'error', self::STATUS_DOWNLOADING => 'downloading', self::STATUS_PAUSED => 'paused', self::STATUS_SEEDING => 'seeding', self::STATUS_COMPLETE => 'complete' ); /** * @var int The torrent id (used by the torrent client, and may change on each reboot) */ private $id; /** * @var string The torrent hashString which can be used to uniquely identify this torrent */ private $hashString = ''; /** * @var string The torrent name */ private $name = ''; /** * @var int Size of the torrent in bytes */ private $size = 0; /** * @var int Torrent status must be in the $statuses array */ private $status = self::STATUS_UNKNOWN; /** * @var string A string containing an error message */ private $errorString = ''; /** * @var int Download speed in bytes */ private $downloadSpeed = 0; /** * @var int Upload speed in bytes */ private $uploadSpeed = 0; /** * @var float Percentage download completion */ private $percentDone = 0.0; /** * @var int Number of bytes downloaded */ private $bytesDownloaded = 0; /** * @var int Number of bytes uploaded */ private $bytesUploaded = 0; /** * @var float Seeding ratio */ private $seedRatio = 0.0; /** * @var File[] A list of files within the torrent */ private $files = array(); /** * @constructor * * @param int $id The id used by the torrent client (may change on each reboot) * @param string $hashString Uniquely identifiable hash string (remains constant) */ public function __construct($id, $hashString) { $this->id = $id; $this->hashString = $hashString; } /** * Set the torrent name * * @param string $name The name of the torrent */ public function setName($name) { $this->name = $name; } /** * Get torrent name * * @return string The torrent name */ public function getName() { return $this->name; } /** * Set the torrent size in bytes * * @param int $bytes The size of the torrent * * @throws \InvalidArgumentException When an invalid size given */ public function setSize($bytes) { if (is_int($bytes) && $bytes > -1) { $this->size = $bytes; } else { throw new \InvalidArgumentException( 'Invalid torrent size provided. Size should be bigger than "-1" but "%s" given', $bytes ); } } /** * Get torrent size * * @return int The torrent size in bytes */ public function getSize() { return $this->size; } /** * Set the torrent status according to a status within the $statuses array * * @param int $status The status integer (constant representing an integer) * * @throws \InvalidArgumentException When an invalid status integer given */ public function setStatus($status) { if (is_int($status) && isset($this->statuses[$status])) { $this->status = $status; } else { throw new \InvalidArgumentException(sprintf( 'Invalid torrent status provided. Status should be one of "%s", "%s" given.', print_r($this->statuses, true), $status )); } } /** * Get the status integer value * * @return int */ public function getStatus() { return $this->status; } /** * Get the status string * * @return string */ public function getStatusString() { return $this->statuses[$this->status]; } /** * Set error string * * @param string $errorString */ public function setErrorString($errorString) { $this->errorString = $errorString; } /** * Get error string * * @return string */ public function getErrorString() { return $this->errorString; } /** * Set download speed in bytes per second * * @param int $bytesPerSecond * * @throws \InvalidArgumentException When an integer is not provided as the parameter */ public function setDownloadSpeed($bytesPerSecond) { if (is_int($bytesPerSecond) && $bytesPerSecond > -1) { $this->downloadSpeed = $bytesPerSecond; } else { throw new \InvalidArgumentException(sprintf( 'Invalid torrent download speed provided. Download speed should be non-negative integer, "%s" given.', $bytesPerSecond )); } } /** * Get download speed in bytes per second * * @return int */ public function getDownloadSpeed() { return $this->downloadSpeed; } /** * Set upload speed in bytes per second * * @param int $bytesPerSecond * * @throws \InvalidArgumentException When an integer is not provided as the parameter */ public function setUploadSpeed($bytesPerSecond) { if (is_int($bytesPerSecond) && $bytesPerSecond > -1) { $this->uploadSpeed = $bytesPerSecond; } else { throw new \InvalidArgumentException(sprintf( 'Invalid torrent upload speed provided. Upload speed should be non-negative integer, "%s" given.', $bytesPerSecond )); } } /** * Get download speed in bytes per second * * @return int */ public function getUploadSpeed() { return $this->uploadSpeed; } /** * Set number of bytes downloaded * * @param int $numBytes * * @throws \InvalidArgumentException When an integer is not provided as the parameter * * @note Also sets the completion percentage and status to complete if 100% */ public function setBytesDownloaded($numBytes) { if (is_int($numBytes) && $numBytes > -1) { $this->bytesDownloaded = $numBytes; $size = $this->size; $percentDone = function() use ($size, $numBytes) { $size = ($size === 0) ? 1 : $size; $numBytes = ($size > $numBytes) ? $numBytes : 0; if ($size === 0 && $numBytes === 0) { return (float)0; } return (float)number_format(($numBytes / $size) * 100, 2, '.', ''); }; $this->percentDone = $percentDone(); if ($this->percentDone === 100 || $numBytes === $this->size) { $this->status = self::STATUS_COMPLETE; } } else { throw new \InvalidArgumentException(sprintf( 'Invalid torrent bytes downloaded provided. Amount should be non-negative integer, "%s" given.', $numBytes )); } } /** * Get number of bytes downloaded * * @return int */ public function getBytesDownloaded() { return $this->bytesDownloaded; } /** * Set number of bytes uploaded * * @param int $numBytes * * @throws \InvalidArgumentException * * @note Also sets the seed ratio percentage */ public function setBytesUploaded($numBytes) { if (is_int($numBytes) && $numBytes > -1) { $this->bytesUploaded = $numBytes; $downloaded = $this->bytesDownloaded; $seedRatio = function() use ($downloaded, $numBytes) { $downloaded = ($downloaded === 0) ? 1 : $downloaded; $numBytes = ($downloaded > $numBytes) ? $numBytes : 0; if ($downloaded === 0 && $numBytes === 0) { return (float)0; } return (float)number_format(($numBytes / $downloaded) * 100, 2, '.', ''); }; $this->seedRatio = $seedRatio(); } else { throw new \InvalidArgumentException(sprintf( 'Invalid torrent bytes uploaded provided. Amount should be non-negative integer, "%s" given.', $numBytes )); } } /** * Get number of bytes uploaded * * @return int */ public function getBytesUploaded() { return $this->bytesUploaded; } /** * Add a file to the torrent * * @param File $file */ public function addFile(File $file) { if (!in_array($file, $this->files)) { $this->files[] = $file; } } /** * Get the files list * * @return File[] */ public function getFiles() { return $this->files; } /** * Get a specific File by name * * @param string $name * * @throws FileNotFoundException When the file does not exist with the given name * * @return File The found file */ public function getFile($name) { $files = array_values(array_filter($this->files, function($file) use ($name) { /** @var File $file */ return strtolower($file->getName()) === strtolower($name); })); if (!empty($files)) { return $files[0]; } else { throw new FileNotFoundException(sprintf( 'File with name: "%s" not found for torrent: "%s"', $name, $this->name )); } } /** * Get whether or not the torrent has completed both downloading and seeding * * @return bool */ public function isComplete() { return ($this->status === self::STATUS_COMPLETE); } }

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.00318.18
8.3.50.0200.00321.94
8.3.40.0030.01218.73
8.3.30.0090.00618.90
8.3.20.0000.00820.16
8.3.10.0000.00823.71
8.3.00.0050.00319.13
8.2.180.0000.01625.92
8.2.170.0090.00618.82
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0000.01526.16
8.2.120.0030.00622.22
8.2.110.0000.00920.57
8.2.100.0120.00017.78
8.2.90.0030.00619.66
8.2.80.0000.00818.61
8.2.70.0050.00317.63
8.2.60.0030.00717.93
8.2.50.0060.00318.07
8.2.40.0000.00818.05
8.2.30.0030.00617.98
8.2.20.0000.00817.70
8.2.10.0050.00318.13
8.2.00.0080.00317.70
8.1.280.0160.00325.92
8.1.270.0040.00424.66
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00319.01
8.1.230.0060.00619.28
8.1.220.0040.00417.76
8.1.210.0040.00418.77
8.1.200.0070.00317.22
8.1.190.0030.00617.23
8.1.180.0060.00318.10
8.1.170.0080.00018.68
8.1.160.0000.00818.77
8.1.150.0040.00418.58
8.1.140.0040.00417.42
8.1.130.0000.00717.92
8.1.120.0000.00917.37
8.1.110.0040.00717.41
8.1.100.0050.00217.41
8.1.90.0000.00817.29
8.1.80.0000.00717.33
8.1.70.0040.00417.34
8.1.60.0050.00317.54
8.1.50.0030.00517.50
8.1.40.0000.00817.49
8.1.30.0000.00817.50
8.1.20.0000.00817.62
8.1.10.0040.00417.46
8.1.00.0080.00017.46
8.0.300.0080.00018.77
8.0.290.0040.00416.75
8.0.280.0000.00718.36
8.0.270.0000.00717.25
8.0.260.0070.00017.24
8.0.250.0030.00616.91
8.0.240.0000.00716.82
8.0.230.0000.00716.94
8.0.220.0000.00716.84
8.0.210.0040.00416.74
8.0.200.0030.00316.89
8.0.190.0030.00616.89
8.0.180.0070.00016.93
8.0.170.0050.00316.82
8.0.160.0050.00316.81
8.0.150.0080.00016.75
8.0.140.0000.00716.83
8.0.130.0000.00613.27
8.0.120.0050.00316.77
8.0.110.0040.00416.88
8.0.100.0050.00316.74
8.0.90.0000.00716.68
8.0.80.0030.01316.92
8.0.70.0000.00816.88
8.0.60.0000.00816.91
8.0.50.0000.00716.72
8.0.30.0080.01116.98
8.0.20.0080.01117.40
8.0.10.0050.00316.99
8.0.00.0080.01216.78
7.4.330.0000.00515.01
7.4.320.0000.00616.39
7.4.300.0070.00016.58
7.4.290.0130.00016.48
7.4.280.0050.00216.48
7.4.270.0080.00016.50
7.4.260.0070.00016.37
7.4.250.0030.00516.55
7.4.240.0040.00416.54
7.4.230.0070.00016.48
7.4.220.0070.00716.36
7.4.210.0050.01416.54
7.4.200.0040.00416.38
7.4.190.0040.00416.75
7.4.160.0120.00616.49
7.4.150.0140.00717.40
7.4.140.0060.01217.86
7.4.130.0100.01016.40
7.4.120.0030.01316.51
7.4.110.0090.00916.49
7.4.100.0090.00916.50
7.4.90.0150.00316.54
7.4.80.0070.01019.39
7.4.70.0130.00316.33
7.4.60.0040.01616.64
7.4.50.0000.00916.41
7.4.40.0070.01122.77
7.4.30.0030.01516.63
7.4.00.0080.00714.66
7.3.330.0030.00613.06
7.3.320.0050.00013.28
7.3.310.0030.00316.30
7.3.300.0030.00316.27
7.3.290.0070.00716.27
7.3.280.0090.00716.29
7.3.270.0130.00317.40
7.3.260.0150.00416.52
7.3.250.0100.00816.39
7.3.240.0110.01116.28
7.3.230.0130.00516.46
7.3.210.0150.00316.31
7.3.200.0130.01019.39
7.3.190.0060.01716.50
7.3.180.0130.00316.13
7.3.170.0070.01016.58
7.3.160.0170.00716.61
7.3.120.0090.00614.84
7.3.110.0060.00914.52
7.3.100.0090.00614.73
7.3.90.0030.00614.67
7.3.80.0040.01114.73
7.3.70.0060.00314.85
7.3.60.0060.00314.46
7.3.50.0060.00914.56
7.3.40.0040.00814.76
7.3.30.0120.00314.52
7.3.20.0090.00616.17
7.3.10.0000.01416.34
7.3.00.0070.00716.38
7.2.330.0030.01416.64
7.2.320.0120.00816.55
7.2.310.0100.00716.64
7.2.300.0060.01016.36
7.2.290.0080.00916.20
7.2.250.0030.01415.09
7.2.240.0090.00514.93
7.2.230.0060.00614.82
7.2.220.0060.00914.75
7.2.210.0030.00915.09
7.2.200.0090.00614.69
7.2.190.0060.00314.82
7.2.180.0070.01014.95
7.2.170.0060.00914.83
7.2.60.0080.00816.82
7.1.330.0030.01215.61
7.1.320.0100.00315.14
7.1.310.0090.00615.59
7.1.300.0000.00915.59
7.1.290.0060.00915.49
7.1.280.0090.00915.75
7.1.270.0130.00615.46
7.1.260.0030.01015.35
7.1.200.0060.00315.35
7.1.70.0080.00016.70
7.1.60.0160.00919.46
7.1.50.0130.01016.61
7.1.00.0100.07022.30
7.0.200.0250.00314.67
7.0.140.0000.07022.07
7.0.100.0170.08020.02
7.0.90.0070.04719.98
7.0.80.0030.05720.03
7.0.70.0030.06719.93
7.0.60.0230.07720.10
7.0.50.0130.08020.31
7.0.40.0070.06720.09
7.0.30.0100.08020.10
7.0.20.0100.08020.05
7.0.10.0030.09019.95
7.0.00.0100.08320.10
5.6.280.0030.07321.22
5.6.250.0200.07020.70
5.6.240.0070.08020.75
5.6.230.0030.08720.79
5.6.220.0030.08320.65
5.6.210.0100.08320.71
5.6.200.0130.06321.10
5.6.190.0070.07721.24
5.6.180.0070.07721.05
5.6.170.0100.08021.07
5.6.160.0070.07021.15
5.6.150.0170.07021.17
5.6.140.0130.06721.07
5.6.130.0170.07321.24
5.6.120.0030.09321.10
5.6.110.0130.06721.10
5.6.100.0070.04321.13
5.6.90.0000.06021.11
5.6.80.0130.07320.63
5.6.70.0100.07020.56
5.6.60.0070.05320.46
5.6.50.0100.07720.46
5.6.40.0200.06720.39
5.6.30.0070.08320.51
5.6.20.0070.08020.36
5.6.10.0100.06720.59
5.6.00.0170.06720.37
5.5.380.0070.08020.42
5.5.370.0030.08020.46
5.5.360.0130.07720.41
5.5.350.0130.07020.40
5.5.340.0130.06021.00
5.5.330.0030.05320.81
5.5.320.0130.07320.99
5.5.310.0100.06321.00
5.5.300.0070.05720.97
5.5.290.0170.07320.91
5.5.280.0130.08020.99
5.5.270.0030.08020.90
5.5.260.0100.09020.86
5.5.250.0070.08020.66
5.5.240.0130.08020.34
5.5.230.0130.07020.28
5.5.220.0030.04320.27
5.5.210.0000.05020.34
5.5.200.0070.07720.19
5.5.190.0170.06720.31
5.5.180.0070.07720.16
5.5.160.0030.04320.06
5.5.150.0070.08020.23
5.5.140.0070.07720.29
5.5.130.0100.06720.33
5.5.120.0070.06020.30
5.5.110.0070.08320.21
5.5.100.0000.04320.24
5.5.90.0030.08020.08
5.5.80.0070.07720.01
5.5.70.0030.04320.15
5.5.60.0170.06720.22
5.5.50.0000.07020.23
5.5.40.0030.04020.23
5.5.30.0070.07320.14
5.5.20.0030.04720.10
5.5.10.0100.07320.13
5.5.00.0070.08320.04
5.4.450.0130.03319.36
5.4.440.0000.08719.48
5.4.430.0070.08019.36
5.4.420.0100.05319.18
5.4.410.0130.07319.24
5.4.400.0130.08018.85
5.4.390.0030.08019.04
5.4.380.0100.07319.13
5.4.370.0030.07318.84
5.4.360.0070.05719.13
5.4.350.0000.08718.91
5.4.340.0070.07318.89
5.4.320.0070.03719.04
5.4.310.0100.07718.91
5.4.300.0100.07319.18
5.4.290.0030.05719.18
5.4.280.0030.08019.04
5.4.270.0130.07019.04
5.4.260.0030.04719.13
5.4.250.0070.07719.05
5.4.240.0070.08018.90
5.4.230.0100.07319.03
5.4.220.0230.03319.05
5.4.210.0100.07318.96
5.4.200.0030.04719.12
5.4.190.0100.03319.11
5.4.180.0130.07019.04
5.4.170.0200.06319.05
5.4.160.0100.06319.03
5.4.150.0030.08019.17
5.4.140.0030.07716.42
5.4.130.0070.06316.38
5.4.120.0070.04716.40
5.4.110.0000.04716.51
5.4.100.0000.07016.40
5.4.90.0070.06716.49
5.4.80.0070.06716.37
5.4.70.0070.07316.46
5.4.60.0130.07016.53
5.4.50.0070.04016.37
5.4.40.0030.05016.48
5.4.30.0000.08016.45
5.4.20.0030.07716.39
5.4.10.0030.07716.41
5.4.00.0100.07015.82
5.3.290.0170.06714.67
5.3.280.0170.06314.64
5.3.270.0070.07714.71
5.3.260.0070.03714.66
5.3.250.0000.05314.73
5.3.240.0030.04014.58
5.3.230.0030.04714.75
5.3.220.0000.08014.75
5.3.210.0000.04714.57
5.3.200.0100.04314.61
5.3.190.0030.06714.67
5.3.180.0000.08314.65
5.3.170.0070.05314.62
5.3.160.0030.08014.71
5.3.150.0100.04014.75
5.3.140.0030.07714.68
5.3.130.0130.07014.62
5.3.120.0000.06714.73
5.3.110.0070.06714.58
5.3.100.0100.07714.08
5.3.90.0070.04714.16
5.3.80.0130.06014.18
5.3.70.0030.07014.06
5.3.60.0000.08014.05
5.3.50.0070.05014.05
5.3.40.0000.04714.14
5.3.30.0130.07013.86
5.3.20.0030.04713.64
5.3.10.0030.03313.61
5.3.00.0130.04013.74

preferences:
45.79 ms | 401 KiB | 5 Q