3v4l.org

run code in 300+ PHP versions simultaneously
<?php $config = [ 'fetchAs' => PDO::FETCH_CLASS, 'use' => 'mysql', 'drivers' => [ 'mysql' => [ 'host' => '127.0.0.1', # skip resolving localhost go directly to 127.0.0.1 ( Optional ) 'port' => 3306, # default mysql port ( Optional ) 'database' => 'twitbot', 'username' => 'root', 'password' => 'toor', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', # ( Optional ) 'persist' => true, # use persistent connection ( true | false ) 'prefix' => '', # ( Optional ) 'socket' => '', # unix socket example /tmp/mysql.sock, leave blank if you are using host ] ] ]; class Manager{ public $manager; public function __construct( array $config ) { $this->manager = new ConnectionManager( $config ); } public function getConnection() { return $this->manager->createConnection(); } } class ConnectionManager { private $config = []; private $availableDrivers = []; private $supportedDrivers = ['mysql']; public function __construct( array $config ) { $this->config = $config; $this->availableDrivers = PDO::getAvailableDrivers(); } public function createConnection() { if(empty( $this->config['use'] )) throw new Exception('Database driver must be set!', 1); # check if PDO Driver was compiled with PHP $driver = strtolower( $this->config['use'] ); if ( ! in_array( $driver, $this->availableDrivers, true )) throw new Exception('Missing PDO driver ' . $driver, 1); if ( ! in_array( $driver, $this->supportedDrivers, true )) throw new Exception($driver . ' is not supported!', 1); $reflection = new ReflectionClass(ucfirst($driver) . 'Connection'); return $reflection->newInstanceArgs([$this->config])->connect(); } } abstract class Connection { private $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false ]; public $config = []; public function __construct( array $config ) { $this->config = $config; $this->options[ PDO::ATTR_PERSISTENT ] = $this->getDriverKey('persist'); $this->options[ PDO::ATTR_DEFAULT_FETCH_MODE ] = $this->config['fetchAs']; } protected function establishConnection( $dsn = null ) { return new PDO( $dsn, $this->getDriverKey('username'), $this->getDriverKey('password'), $this->options ); } public function getDriverKey( $key = null ) { $value = $this->config['drivers'][ $this->config['use'] ][ $key ]; return ( isset($value) && ! empty($value) ) ? $value : false; } public function setOptions( array $options ) { $this->options = $options; } public function getOptions() { return $this->options; } } class MysqlConnection extends Connection{ private $dsn; public $connection; public function __construct( array $config ) { parent::__construct( $config ); $this->dsn = $this->makeDsn(); } private function makeDsn(){ return ( $this->isUsingSocket( $this->config ) ) ? $this->useSocket() : $this->useHost(); } private function isUsingSocket(){ if( empty($this->getDriverKey('socket')) && ! $this->getDriverKey('socket') ) return false; return ( is_readable($this->getDriverKey('socket')) ) ? true : false; # check if the socket file path is readable } private function isUsingPort() { return ( is_numeric($this->getDriverKey('port')) ) ? ';port=' . $this->getDriverKey('port') : ''; } private function useSocket() { return 'mysql:unix_socket=' . $this->getDriverKey('socket') . ';dbname=' . $this->getDriverKey('database') . ';charset=' . $this->getDriverKey('charset'); } private function useHost() { return 'mysql:host=' . $this->getDriverKey('host') . $this->isUsingPort() . ';dbname=' . $this->getDriverKey('database') . ';charset=' . $this->getDriverKey('charset'); } public function connect() { # check if collation is set if( $this->getDriverKey('collation') ){ #$this->options[ PDO::MYSQL_ATTR_INIT_COMMAND ] = "SET NAMES '" . $this->getDriverKey('charset') . "' COLLATE '" . $this->getDriverKey('collation') . "'"; } return $this->connection = $this->establishConnection( $this->dsn ); } } $manager = new Manager( $config ); var_dump($manager);

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.0080.00816.75
8.3.50.0080.01023.00
8.3.40.0080.00818.75
8.3.30.0110.00418.93
8.3.20.0090.00020.30
8.3.10.0060.00320.39
8.3.00.0050.00320.95
8.2.180.0160.00325.92
8.2.170.0090.00918.85
8.2.160.0100.01022.96
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0030.01226.16
8.2.120.0060.00319.23
8.2.110.0070.00320.21
8.2.100.0070.00717.84
8.2.90.0060.00318.02
8.2.80.0040.00419.25
8.2.70.0150.00518.36
8.2.60.0100.00618.43
8.2.50.0130.00718.45
8.2.40.0130.00718.74
8.2.30.0170.00318.27
8.2.20.0160.00318.83
8.2.10.0140.00518.65
8.2.00.0080.01118.77
8.1.280.0110.00725.92
8.1.270.0030.00623.97
8.1.260.0080.00026.35
8.1.250.0050.00528.09
8.1.240.0090.00022.14
8.1.230.0060.00620.99
8.1.220.0030.00517.74
8.1.210.0060.00318.80
8.1.200.0160.00518.50
8.1.190.0120.00618.38
8.1.180.0100.01018.16
8.1.170.0120.00618.42
8.1.160.0110.00618.36
8.1.150.0120.00818.25
8.1.140.0120.00618.23
8.1.130.0130.00418.41
8.1.120.0090.00918.29
8.1.110.0170.00018.33
8.1.100.0170.00018.26
8.1.90.0080.00818.43
8.1.80.0130.00518.07
8.1.70.0140.00318.48
8.1.60.0160.00518.77
8.1.50.0090.00918.58
8.1.40.0130.00618.67
8.1.30.0050.00518.90
8.1.20.0150.00518.48
8.1.10.0080.00418.73
8.1.00.0040.00718.57
8.0.300.0050.00320.35
8.0.290.0110.00617.86
8.0.280.0040.00417.84
8.0.270.0130.00417.95
8.0.260.0040.00417.92
8.0.250.0000.01118.08
8.0.240.0050.00518.07
8.0.230.0030.00717.95
8.0.220.0030.00717.80
8.0.210.0070.00317.80
8.0.200.0050.00518.06
8.0.190.0080.00318.16
8.0.180.0050.00518.00
8.0.170.0060.00317.96
8.0.160.0000.01117.80
8.0.150.0120.00417.80
8.0.140.0040.00717.90
8.0.130.0090.00017.95
8.0.120.0000.01117.88
8.0.110.0060.00317.94
8.0.100.0050.01117.80
8.0.90.0070.00218.02
8.0.80.0030.00717.80
8.0.70.0070.00417.88
8.0.60.0090.00017.80
8.0.50.0100.00717.80
8.0.30.0040.00417.90
8.0.20.0110.00017.80
8.0.10.0040.00818.02
8.0.00.0140.00517.80
7.4.330.0070.00717.80
7.4.320.0160.00017.80
7.4.300.0130.00317.80
7.4.290.0130.00417.80
7.4.280.0170.00317.80
7.4.270.0090.00917.80
7.4.260.0130.00417.80
7.4.250.0160.00317.80
7.4.240.0190.00017.80
7.4.230.0140.00317.80
7.4.220.0120.00417.80
7.4.210.0110.00617.80
7.4.200.0090.00817.80
7.4.190.0120.00617.80
7.4.180.0140.00417.80
7.4.160.0130.00417.80
7.4.150.0120.00417.80
7.4.140.0120.00417.80
7.4.130.0120.00417.80
7.4.120.0090.00917.80
7.4.110.0150.00217.80
7.4.100.0110.00617.80
7.4.90.0100.00517.80
7.4.80.0180.00017.80
7.4.70.0170.00017.80
7.4.60.0070.01017.80
7.4.50.0060.01117.80
7.4.40.0070.00717.80
7.4.30.0120.00417.80
7.4.20.0130.00417.80
7.4.10.0080.00817.80
7.4.00.0140.00217.80
7.3.330.0090.00917.80
7.3.320.0130.00317.80
7.3.310.0160.00017.80
7.3.300.0130.00317.80
7.3.290.0100.00617.80
7.3.280.0130.00317.80
7.3.270.0000.00917.80
7.3.260.0060.00317.80
7.3.250.0050.00517.80
7.3.240.0000.00917.80
7.3.230.0050.00517.80
7.3.220.0080.00017.80
7.3.210.0000.00917.80
7.3.200.0110.00017.80
7.3.190.0020.00517.80
7.3.180.0110.00017.80
7.3.170.0000.01017.80
7.3.160.0000.00717.80
7.3.150.0040.00417.80
7.3.140.0070.00417.80
7.3.130.0000.01017.80
7.3.120.0030.00517.80
7.3.110.0070.00317.80
7.3.100.0080.00017.80
7.3.90.0100.00717.80
7.3.80.0090.00617.80
7.3.70.0120.00017.80
7.3.60.0100.00517.80
7.3.50.0050.01017.80
7.3.40.0080.00517.80
7.3.30.0090.00417.80
7.3.20.0150.00018.92
7.3.10.0060.01018.49
7.3.00.0090.00618.60
7.2.340.0130.00017.80
7.2.330.0180.00017.80
7.2.320.0150.00317.80
7.2.310.0130.00417.80
7.2.300.0100.00717.80
7.2.290.0110.00317.80
7.2.280.0150.00017.80
7.2.270.0090.00317.80
7.2.260.0110.00417.80
7.2.250.0130.00017.80
7.2.240.0090.00417.80
7.2.230.0120.00417.80
7.2.220.0130.00017.80
7.2.210.0110.00417.80
7.2.200.0120.00417.80
7.2.190.0120.00317.80
7.2.180.0110.00417.80
7.2.170.0100.00517.80
7.2.160.0060.00817.80
7.2.150.0140.00319.19
7.2.140.0090.00519.40
7.2.130.0150.00019.20
7.2.120.0120.00319.31
7.2.110.0060.00919.33
7.2.100.0120.00419.35
7.2.90.0170.00019.25
7.2.80.0160.00319.34
7.2.70.0100.00519.19
7.2.60.0160.00219.16
7.2.50.0130.00419.05
7.2.40.0110.00819.32
7.2.30.0100.00519.33
7.2.20.0080.00819.50
7.2.10.0000.01519.20
7.2.00.0140.00019.36
7.1.330.0170.00018.34
7.1.320.0130.00418.00
7.1.310.0110.00418.18
7.1.300.0140.00018.09
7.1.290.0100.00518.17
7.1.280.0120.00418.13
7.1.270.0140.00017.96
7.1.260.0090.00518.21
7.1.250.0050.01117.99
7.1.240.0120.00418.18
7.1.230.0090.00618.30
7.1.220.0070.00718.23
7.1.210.0090.00518.21
7.1.200.0100.00618.24
7.1.190.0140.00018.32
7.1.180.0160.00018.25
7.1.170.0140.00217.94
7.1.160.0100.00318.34
7.1.150.0100.00518.24
7.1.140.0140.00018.27
7.1.130.0070.00718.21
7.1.120.0110.00318.03
7.1.110.0120.00417.99
7.1.100.0120.00217.96
7.1.90.0090.00617.81
7.1.80.0150.00118.16
7.1.70.0120.00417.95
7.1.60.0110.00418.13
7.1.50.0070.00718.09
7.1.40.0110.00318.16
7.1.30.0110.00418.01
7.1.20.0080.00518.16
7.1.10.0110.00317.84
7.1.00.0140.00418.33
7.0.330.0100.00517.91
7.0.320.0030.01117.97
7.0.310.0110.00417.90
7.0.300.0060.01017.80
7.0.290.0030.01017.80
7.0.280.0050.00917.82
7.0.270.0120.00217.92
7.0.260.0070.00717.80
7.0.250.0100.00317.93
7.0.240.0090.00617.87
7.0.230.0110.00317.80
7.0.220.0070.00718.12
7.0.210.0120.00417.80
7.0.200.0100.00517.80
7.0.190.0100.00517.80
7.0.180.0050.00817.86
7.0.170.0120.00318.06
7.0.160.0040.00917.95
7.0.150.0120.00317.94
7.0.140.0160.00017.80
7.0.130.0160.00017.80
7.0.120.0110.00417.89
7.0.110.0100.00718.21
7.0.100.0120.00217.88
7.0.90.0130.00017.85
7.0.80.0100.00617.99
7.0.70.0090.00617.98
7.0.60.0080.00817.99
7.0.50.0110.00217.84
7.0.40.0130.00018.05
7.0.30.0100.00518.00
7.0.20.0090.00517.91
7.0.10.0090.00618.03
7.0.00.0040.00917.92
5.6.400.0130.00017.80
5.6.390.0110.00417.80
5.6.380.0100.00517.80
5.6.370.0000.01217.80
5.6.360.0130.00017.80
5.6.350.0070.00717.80
5.6.340.0060.00717.80
5.6.330.0080.00517.80
5.6.320.0070.00717.80
5.6.310.0130.00317.80
5.6.300.0130.00017.80
5.6.290.0100.00317.80
5.6.280.0110.00217.80
5.6.270.0130.00317.80
5.6.260.0110.00317.80
5.6.250.0100.00317.80
5.6.240.0080.00517.80
5.6.230.0100.00317.80
5.6.220.0100.00317.80
5.6.210.0140.00017.80
5.6.200.0110.00617.80
5.6.190.0060.00917.80
5.6.180.0150.00017.80
5.6.170.0050.00917.80
5.6.160.0090.00517.80
5.6.150.0100.00717.80
5.6.140.0090.00617.80
5.6.130.0100.00517.80
5.6.120.0120.00017.80
5.6.110.0000.01317.80
5.6.100.0090.00617.80
5.6.90.0090.00417.80
5.6.80.0070.00517.80
5.6.70.0030.01017.80
5.6.60.0110.00417.80
5.6.50.0070.00717.80
5.6.40.0050.00817.80
5.6.30.0090.00617.80
5.6.20.0040.00917.80
5.6.10.0130.00017.80
5.6.00.0130.00017.80
5.5.380.0130.00017.80
5.5.370.0140.00317.80
5.5.360.0070.00817.80
5.5.350.0050.01017.80
5.5.340.0080.00417.80
5.5.330.0060.00917.80
5.5.320.0100.00317.80
5.5.310.0090.00317.80
5.5.300.0060.00617.80
5.5.290.0090.00417.80
5.5.280.0130.00017.80
5.5.270.0100.00317.80
5.5.260.0140.00017.80
5.5.250.0050.00917.80
5.5.240.0060.00617.80
5.5.230.0090.00417.80
5.5.220.0120.00017.80
5.5.210.0120.00017.80
5.5.200.0100.00317.80
5.5.190.0070.00717.80
5.5.180.0140.00017.80
5.5.170.0100.00317.80
5.5.160.0090.00417.80
5.5.150.0130.00017.80
5.5.140.0120.00317.80
5.5.130.0070.00717.80
5.5.120.0030.01017.80
5.5.110.0080.00417.80
5.5.100.0130.00017.80
5.5.90.0090.00517.80
5.5.80.0090.00417.80
5.5.70.0040.00817.80
5.5.60.0040.00817.80
5.5.50.0080.00417.80
5.5.40.0100.00317.80
5.5.30.0030.00917.80
5.5.20.0110.00317.80
5.5.10.0080.00417.80
5.5.00.0100.00317.80
5.4.450.0100.00017.80
5.4.440.0050.00517.80
5.4.430.0000.01117.80
5.4.420.0080.00417.80
5.4.410.0080.00317.80
5.4.400.0050.00517.80
5.4.390.0100.00017.80
5.4.380.0120.00017.80
5.4.370.0050.00617.80
5.4.360.0060.00617.80
5.4.350.0100.00317.80
5.4.340.0050.00717.80
5.4.330.0040.00717.80
5.4.320.0060.00617.80
5.4.310.0050.00517.80
5.4.300.0100.00317.80
5.4.290.0090.00217.80
5.4.280.0040.00717.80
5.4.270.0070.00317.80
5.4.260.0050.00517.80
5.4.250.0080.00317.80
5.4.240.0100.00217.80
5.4.230.0060.00617.80
5.4.220.0070.00317.80
5.4.210.0100.00017.80
5.4.200.0080.00417.80
5.4.190.0090.00017.80
5.4.180.0090.00517.80
5.4.170.0080.00317.80
5.4.160.0100.00317.80
5.4.150.0100.00017.80
5.4.140.0040.00817.80
5.4.130.0050.00517.80
5.4.120.0030.00617.80
5.4.110.0070.00417.80
5.4.100.0060.00317.80
5.4.90.0080.00317.80
5.4.80.0070.00317.80
5.4.70.0070.00417.80
5.4.60.0080.00317.80
5.4.50.0030.00717.80
5.4.40.0070.00317.80
5.4.30.0080.00317.80
5.4.20.0130.00017.80
5.4.10.0030.00717.80
5.4.00.0060.00617.80

preferences:
45.63 ms | 401 KiB | 5 Q