3v4l.org

run code in 300+ PHP versions simultaneously
<?php //https://github.com/nicolasff/phpredis class RedisMultiErrHandler { private $obj; private $ip; private $port; private $timeout; private $m; private $type; private $commands; public function __construct($redis,$type,$ip,$port,$timeout=0) { $this->ip=$ip; $this->port=$port; $this->timeout=$timeout; $this->type=$type; $this->obj=$redis; $this->m=$this->obj->multi($type); } private function rconnect() { $this->obj=new Redis; $this->obj->connect($this->ip,$this->port,$this->timeout) or die('Error connecting redis2'); $this->m=$this->obj->multi($this->type); } public function __call($name, $arguments) { $this->commands[]=array('name'=>$name, 'arguments'=>$arguments); return $this; } private function handle_exception($e) { $err=$e->getMessage(); $msg=''; foreach($this->commands as $command) { $msg.="Multi sent\tcall ".$command['name']."\targs ".implode(" ",$command['arguments'])."\n"; } $msg.="Caught exception: ".$err."\n"; if(DEBUG_INFO) { $handle2=fopen('redis_multi_log.txt','a'); fwrite($handle2,date('H:i:s')."\t$msg"); fclose($handle2); } if(substr(trim($err),0,37)=='Caught exception: protocol error, got') die('bye'); $this->rconnect(); } public function exec() { $i=0; while(true) { foreach($this->commands as $command) { call_user_func_array(array($this->m, $command['name']), $command['arguments']); // call_user_func_array(array( $this->obj, $command['name']), $command['arguments']); } try{ return $this->m->exec(); break; } catch (Exception $e) { $this->handle_exception($e); if($i<5) $i++; else die('5 time mredis lug'); } } } } class Redis_Cache { private $obj; private $ip; private $port; private $timeout; //public $site_id = 0; protected static $key_request = array(); // private static $instance; protected static $count_requests = 0; /* public static function getInstance() { self::$count_requests++; return (self::$instance === null) ? self::$instance = new self() : self::$instance; }*/ public function set_settings($redis , $ip = '127.0.0.1' , $port ='6379' , $timeout = 0) { $this->ip=$ip; $this->port=$port; $this->timeout=$timeout; $this->obj = $redis; $this->rconnect($redis); } private function rconnect() { $this->obj->pconnect($this->ip,$this->port,$this->timeout) or die('Error connecting redis'); } public function __call($name, $arguments) { $i=0; self::$key_request[] = $arguments[0]; while(true) { try{ j2_timeStamps::getInstance()->addCacheTime($arguments[0] . ' (' . $name . ')'); $return = call_user_func_array(array($this->obj, $name), $arguments); j2_timeStamps::getInstance()->addCacheTime($arguments[0] . ' (' . $name . ')'); return $return; break; } catch (Exception $e) { $this->handle_exception($e,$name,$arguments); if($i<5) $i++; else die('5 time redis lug'); } } } private function handle_exception($e,$name,$args) { $err=$e->getMessage(); $msg="Caught exception: ".$err."\tcall ".$name."\targs ".implode(" ",$args)."\n"; if(DEBUG_INFO) { $handle2=fopen('redis_log.txt','a'); fwrite($handle2,date('H:i:s')."\t$msg"); fclose($handle2); } if(substr(trim($err),0,37)=='Caught exception: protocol error, got') die('bye'); $this->rconnect(); } /* public function set($name , $data) { return $this->obj->set($name , serialize($data)); } */ public function set($name , $time=null , $data) { // self::$key_request[] = $name; if (empty($time)) { j2_timeStamps::getInstance()->addCacheTime($name . ' (set)'); $return = $this->obj->set($name , serialize($data)); j2_timeStamps::getInstance()->addCacheTime($name . ' (set)'); return $return; } else { j2_timeStamps::getInstance()->addCacheTime($name . ' (setex)'); $return = $this->obj->setex($name , $time , serialize($data)); j2_timeStamps::getInstance()->addCacheTime($name . ' (setex)'); return $return; } } public function destroy($name) { j2_timeStamps::getInstance()->addCacheTime($name . ' (del)'); $return = $this->obj->del($name); j2_timeStamps::getInstance()->addCacheTime($name . ' (del)'); return $return; } public function get($name) { j2_timeStamps::getInstance()->addCacheTime($name . ' (get)'); $return = unserialize($this->obj->get($name)); j2_timeStamps::getInstance()->addCacheTime($name . ' (get)'); return $return; } public function get_real($name) { j2_timeStamps::getInstance()->addCacheTime($name . ' (get_real)'); $return = $this->obj->get($name); j2_timeStamps::getInstance()->addCacheTime($name . ' (get_real)'); return $return; } public function get_keys_by_prefix($name) { j2_timeStamps::getInstance()->addCacheTime($name . ' (keys)'); $return = $this->obj->keys($name . "*"); j2_timeStamps::getInstance()->addCacheTime($name . ' (keys)'); return $return; } //purges all cache public function purge() { j2_timeStamps::getInstance()->addCacheTime($name . ' (flushAll)'); $return = $this->obj->flushAll(); j2_timeStamps::getInstance()->addCacheTime($name . ' (flushAll)'); return $return; } /* public function exists($name) { return $this->obj->exists($name); } */ public function destroy_by_prefix($prefix) { j2_timeStamps::getInstance()->addCacheTime($prefix . ' (destroy_by_prefix)'); $return = $this->destroy($this->obj->keys($prefix . "*")); j2_timeStamps::getInstance()->addCacheTime($prefix . ' (destroy_by_prefix)'); return $return; } public function get_requests() { return self::$count_requests; } public function get_key_requests() { return self::$key_request; } public function lifetime($name) { j2_timeStamps::getInstance()->addCacheTime($name . ' (TTL)'); $return = $this->obj->TTL($name); j2_timeStamps::getInstance()->addCacheTime($name . ' (TTL)'); return $return; } /* public function sAdd($keys , $member) { return $this->obj->sAdd($keys , $member); }/**/ /* public function multi($type) { return new RedisMultiErrHandler($this->obj,$type,$this->ip,$this->port,$this->timeout); } */ } /** * Сохраняет данные кеша в статическом массыве, чтобы по несколько раз не дергать кеш */ class Cache extends Redis_Cache { private static $instance; static $static_cache = array(); public static function getInstance() { parent::$count_requests++; return (self::$instance === null) ? self::$instance = new self() : self::$instance; } public function destroy($name, $static_cache = true) { if(is_array($name)) { foreach ($name as $value) { $key = md5($value); if($static_cache) { unset(self::$static_cache[$key]); } parent::destroy($value); } return true; } $key = md5($name); if(array_key_exists($key, self::$static_cache)) { unset(self::$static_cache[$key]); } return parent::destroy($name); } public function get($name, $static_cache = true) { if($static_cache) { $key = md5($name); if(array_key_exists($key, self::$static_cache)) { return self::$static_cache[$key]; } } $return = parent::get($name); if($static_cache) { if($return !== false) { self::$static_cache[$key] = $return; } } return $return; } public function set($name , $time=null , $data = null, $static_cache = true) { $key = md5($name); if($static_cache) { self::$static_cache[$key] = $data; } return parent::set($name, $time, $data); } public function purge() { self::$static_cache = array(); return parent::purge(); } public function hSet($name, $index, $data, $static_cache = true) { if($static_cache) { $key = md5($name); //$index_key = md5($index); $index_key = $index; if(!array_key_exists($key, self::$static_cache)) { self::$static_cache[$key] = array(); } self::$static_cache[$key][$index_key] = $data; } return parent::hSet($name, $index, $data); } public function hGet($name, $index, $static_cache = true) { if($static_cache) { $key = md5($name); //$index_key = md5($index); $index_key = $index; if(array_key_exists($key, self::$static_cache) && array_key_exists($index, self::$static_cache[$key])) { return self::$static_cache[$key][$index_key]; } } $return = parent::hGet($name, $index); if($static_cache) { if($return !== false) { if(!array_key_exists($key, self::$static_cache)) { self::$static_cache[$key] = array(); } self::$static_cache[$key][$index_key] = $return; } } return $return; } /* public function hGetAll($name) { $key = md5($name); if(array_key_exists($key, self::$static_cache)) { return self::$static_cache[$key]; } $return = parent::hGetAll($name); if($return !== false) { self::$static_cache[$key] = $return; } return $return; }*/ }

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.0090.00916.63
8.3.50.0110.00721.93
8.3.40.0120.00318.63
8.3.30.0140.00019.04
8.3.20.0050.00320.47
8.3.10.0050.00321.86
8.3.00.0040.00419.25
8.2.180.0060.01318.16
8.2.170.0080.00822.96
8.2.160.0100.00320.63
8.2.150.0050.00324.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00422.08
8.2.110.0070.00320.47
8.2.100.0100.00317.85
8.2.90.0040.00418.34
8.2.80.0050.00317.97
8.2.70.0070.00317.63
8.2.60.0060.00317.80
8.2.50.0040.00818.07
8.2.40.0060.00318.05
8.2.30.0050.00317.95
8.2.20.0030.00517.57
8.2.10.0000.00818.12
8.2.00.0030.00517.77
8.1.280.0120.00925.92
8.1.270.0040.00422.27
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0080.00022.31
8.1.230.0080.00420.97
8.1.220.0030.00517.74
8.1.210.0000.00818.81
8.1.200.0000.00917.13
8.1.190.0030.00617.28
8.1.180.0000.00818.10
8.1.170.0060.00618.68
8.1.160.0030.00621.98
8.1.150.0000.00718.55
8.1.140.0040.00417.55
8.1.130.0070.00017.89
8.1.120.0000.00817.53
8.1.110.0030.00517.47
8.1.100.0030.00517.45
8.1.90.0000.00717.42
8.1.80.0030.00517.35
8.1.70.0040.00417.33
8.1.60.0030.00617.57
8.1.50.0040.00417.43
8.1.40.0040.00417.57
8.1.30.0040.00417.51
8.1.20.0040.00417.54
8.1.10.0050.00317.50
8.1.00.0030.00617.34
8.0.300.0040.00420.24
8.0.290.0030.00517.04
8.0.280.0000.00718.35
8.0.270.0040.00417.27
8.0.260.0030.00316.88
8.0.250.0070.00016.90
8.0.240.0000.00716.97
8.0.230.0000.00716.98
8.0.220.0000.00716.92
8.0.210.0000.00716.88
8.0.200.0030.00316.98
8.0.190.0070.00017.05
8.0.180.0050.00316.99
8.0.170.0080.00016.88
8.0.160.0000.00716.86
8.0.150.0040.00416.89
8.0.140.0000.00816.81
8.0.130.0090.00013.37
8.0.120.0040.00416.91
8.0.110.0000.00816.97
8.0.100.0000.00716.90
8.0.90.0030.00516.85
8.0.80.0110.00516.84
8.0.70.0000.00816.98
8.0.60.0000.00816.75
8.0.50.0080.00016.73
8.0.30.0090.01017.13
8.0.20.0130.00617.40
8.0.10.0030.00517.05
8.0.00.0090.01116.64
7.4.330.0000.00615.00
7.4.320.0000.00716.42
7.4.300.0030.00316.53
7.4.290.0070.00016.38
7.4.280.0060.00316.53
7.4.270.0040.00416.58
7.4.260.0040.00416.52
7.4.250.0040.00416.63
7.4.240.0000.00716.65
7.4.230.0070.00016.38
7.4.220.0070.01616.62
7.4.210.0080.00716.56
7.4.200.0040.00416.36
7.4.190.0000.00816.66
7.4.160.0080.00816.36
7.4.150.0130.00617.40
7.4.140.0130.01017.86
7.4.130.0090.00916.57
7.4.120.0060.01216.57
7.4.110.0100.01016.59
7.4.100.0100.01016.65
7.4.90.0080.00916.38
7.4.80.0040.01619.39
7.4.70.0070.01016.46
7.4.60.0070.01016.53
7.4.50.0040.00416.37
7.4.40.0110.00722.77
7.4.30.0090.00916.51
7.4.00.0120.00314.98
7.3.330.0000.00513.16
7.3.320.0000.00613.05
7.3.310.0000.00716.35
7.3.300.0000.00716.34
7.3.290.0030.01016.31
7.3.280.0090.00716.26
7.3.270.0070.01017.40
7.3.260.0120.00716.27
7.3.250.0110.01116.43
7.3.240.0070.01016.60
7.3.230.0030.01416.39
7.3.210.0060.01216.49
7.3.200.0170.00619.39
7.3.190.0130.01016.41
7.3.180.0070.01016.57
7.3.170.0170.00016.28
7.3.160.0100.01016.59
7.3.120.0030.01314.93
7.3.110.0000.01514.70
7.3.100.0060.00914.54
7.3.90.0070.00714.71
7.3.80.0030.00914.44
7.3.70.0060.00914.69
7.3.60.0040.00714.71
7.3.50.0040.00714.44
7.3.40.0030.00614.82
7.3.30.0030.01214.75
7.3.20.0070.00716.45
7.3.10.0000.00916.42
7.3.00.0120.00316.27
7.2.330.0140.00416.57
7.2.320.0170.00716.45
7.2.310.0060.01516.63
7.2.300.0070.01016.39
7.2.290.0080.01516.35
7.2.240.0110.00614.87
7.2.230.0040.01414.94
7.2.220.0030.01314.82
7.2.210.0000.01514.79
7.2.200.0030.00914.91
7.2.190.0060.00914.79
7.2.180.0000.01814.85
7.2.170.0030.01315.05
7.2.160.0000.01414.75
7.2.150.0030.01216.85
7.2.140.0000.01616.79
7.2.130.0000.01116.89
7.2.120.0000.01816.67
7.2.110.0060.00616.61
7.2.100.0040.01416.79
7.2.90.0090.00616.52
7.2.80.0060.00916.66
7.2.70.0110.00316.79
7.2.60.0090.00916.54
7.2.50.0030.01316.72
7.2.40.0000.01416.48
7.2.30.0060.00616.53
7.2.20.0120.00316.77
7.2.10.0080.00816.89
7.2.00.0050.00717.96
7.1.330.0030.01015.69
7.1.320.0080.00315.66
7.1.310.0000.01415.63
7.1.300.0070.00715.60
7.1.290.0060.00615.62
7.1.280.0060.00615.67
7.1.270.0070.00715.59
7.1.260.0000.01515.63
7.1.250.0060.00915.64
7.1.100.0090.00618.05
7.1.70.0030.00617.10
7.1.60.0030.00716.95
7.1.50.0100.01016.82
7.1.00.0000.07722.32
7.0.200.0090.00916.38
7.0.140.0100.06722.01
7.0.90.0100.08019.96
7.0.80.0070.08720.04
7.0.70.0070.06319.93
7.0.60.0070.08319.86
7.0.50.0130.03020.37
7.0.40.0070.07320.06
7.0.30.0070.08320.15
7.0.20.0000.06320.13
7.0.10.0030.05020.14
7.0.00.0030.09319.99
5.6.280.0070.07321.00
5.6.240.0130.07320.55
5.6.230.0030.08320.57
5.6.220.0100.03320.54
5.6.210.0070.03720.77
5.6.200.0130.07021.11
5.6.190.0070.03321.13
5.6.180.0070.04321.12
5.6.170.0070.04021.05
5.6.160.0030.08321.18
5.6.150.0030.05321.09
5.6.140.0030.07721.20
5.6.130.0000.04321.03
5.6.120.0070.08021.13
5.6.110.0070.04721.04
5.6.100.0030.08321.20
5.6.90.0070.07321.23
5.6.80.0030.03320.51
5.6.70.0100.03020.51
5.6.60.0130.06720.51
5.6.50.0000.06320.50
5.6.40.0130.07020.50
5.6.30.0030.05020.61
5.6.20.0030.04020.38
5.6.10.0000.03720.54
5.6.00.0070.03020.45
5.5.380.0200.08020.42
5.5.370.0070.05020.49
5.5.360.0030.09020.37
5.5.350.0030.07720.45
5.5.340.0100.03020.96
5.5.330.0030.05720.89
5.5.320.0070.03720.82
5.5.310.0030.04020.89
5.5.300.0070.05020.88
5.5.290.0000.07720.86
5.5.280.0030.09020.96
5.5.270.0000.04020.88
5.5.260.0130.07720.84
5.5.250.0130.06320.53
5.5.240.0130.06020.27
5.5.230.0030.05320.24
5.5.220.0130.07320.29
5.5.210.0130.07020.34
5.5.200.0030.04020.38
5.5.190.0070.03720.32
5.5.180.0030.04020.34
5.5.160.0100.03720.35
5.5.150.0030.04720.19
5.5.140.0100.06320.30
5.5.130.0130.07320.17
5.5.120.0070.08020.36
5.5.110.0070.07720.21
5.5.100.0070.09320.04
5.5.90.0070.05720.05
5.5.80.0030.04320.24
5.5.70.0030.04720.19
5.5.60.0070.06320.18
5.5.50.0100.03720.29
5.5.40.0070.04020.23
5.5.30.0170.06019.98
5.5.20.0070.09320.14
5.5.10.0070.07720.12
5.5.00.0070.08320.09
5.4.450.0100.07319.39
5.4.440.0000.09019.45
5.4.430.0030.08719.52
5.4.420.0030.03719.37
5.4.410.0130.04719.10
5.4.400.0030.03319.08
5.4.390.0130.07319.16
5.4.380.0070.04718.97
5.4.370.0100.02719.18
5.4.360.0000.05019.23
5.4.350.0030.07019.07
5.4.340.0030.05319.13
5.4.320.0000.03719.14
5.4.310.0030.04019.10
5.4.300.0070.07019.09
5.4.290.0070.05018.92
5.4.280.0030.03318.92
5.4.270.0030.05719.12
5.4.260.0100.07019.06
5.4.250.0000.08319.09
5.4.240.0030.06019.13
5.4.230.0100.04318.87
5.4.220.0200.06719.05
5.4.210.0030.04318.96
5.4.200.0070.06019.08
5.4.190.0070.06719.11
5.4.180.0030.08319.04
5.4.170.0130.06318.91
5.4.160.0130.06719.11
5.4.150.0070.04318.94
5.4.140.0030.08016.56
5.4.130.0070.07716.48
5.4.120.0100.03716.38
5.4.110.0030.03716.56
5.4.100.0070.03316.45
5.4.90.0030.03716.59
5.4.80.0030.07316.51
5.4.70.0030.07016.41
5.4.60.0000.05716.50
5.4.50.0030.07016.54
5.4.40.0030.05016.42
5.4.30.0030.04016.48
5.4.20.0030.04316.36
5.4.10.0200.05316.41
5.4.00.0030.06015.91
5.3.290.0130.06014.88
5.3.280.0100.07014.70
5.3.270.0170.06714.69
5.3.260.0070.06014.79
5.3.250.0100.07714.83
5.3.240.0100.04014.74
5.3.230.0030.05014.72
5.3.220.0030.08314.61
5.3.210.0030.06714.61
5.3.200.0030.03714.74
5.3.190.0170.04714.66
5.3.180.0030.05014.62
5.3.170.0030.04314.71
5.3.160.0030.05014.80
5.3.150.0070.07314.78
5.3.140.0030.09014.73
5.3.130.0000.04314.67
5.3.120.0100.07014.61
5.3.110.0070.07314.73
5.3.100.0170.06714.13
5.3.90.0000.04714.23
5.3.80.0070.07014.15
5.3.70.0070.05314.19
5.3.60.0100.07014.17
5.3.50.0030.04713.96
5.3.40.0030.07014.20
5.3.30.0030.07713.93
5.3.20.0000.03713.74
5.3.10.0070.03013.75
5.3.00.0000.03713.86

preferences:
43.05 ms | 401 KiB | 5 Q