3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function retry($retries, callable $fn) { while (true) { try { return $fn(); $retries--; } catch (\Exception $e) { if (!$retries) { throw new \Exception('', 0, $e); } } } } $fn = function() { if ($GLOBALS['counter'] > 0) { $GLOBALS['counter']--; throw new \Exception('Try again'); } return 'something successfull'; }; $start = microtime(true); try { $GLOBALS['counter'] = 999999; retry(1000000, $fn); } catch (\Exception $e) {} echo 'Retry finished in: ' . (microtime(true) -$start) . "\n";
Output for 7.1.0
Retry finished in: 0.56308698654175
Output for 7.0.14
Retry finished in: 0.078337907791138
Output for 7.0.6
Retry finished in: 0.84681177139282
Output for 7.0.5
Retry finished in: 0.92169404029846
Output for 7.0.4
Retry finished in: 0.84688305854797
Output for 7.0.3
Retry finished in: 0.84908294677734
Output for 7.0.2
Retry finished in: 0.9614269733429
Output for 7.0.1
Retry finished in: 0.85173201560974
Output for 7.0.0
Retry finished in: 0.84592294692993
Output for 5.6.28
Retry finished in: 1.5408890247345
Output for 5.6.21
Retry finished in: 1.6507270336151
Output for 5.6.20
Retry finished in: 1.7510800361633
Output for 5.6.19
Retry finished in: 1.3803691864014
Output for 5.6.18
Retry finished in: 1.47576212883
Output for 5.6.17
Retry finished in: 1.7428278923035
Output for 5.6.16
Retry finished in: 1.693706035614
Output for 5.6.15
Retry finished in: 1.7186961174011
Output for 5.6.14
Retry finished in: 1.7239558696747
Output for 5.6.13
Retry finished in: 1.7132120132446
Output for 5.6.12
Retry finished in: 1.6038978099823
Output for 5.6.11
Retry finished in: 1.6989929676056
Output for 5.6.10
Retry finished in: 1.6844761371613
Output for 5.6.9
Retry finished in: 1.6197319030762
Output for 5.6.8
Retry finished in: 1.6676042079926
Output for 5.6.7
Retry finished in: 1.358412027359
Output for 5.5.35
Retry finished in: 1.4668788909912
Output for 5.5.34
Retry finished in: 1.6689789295197
Output for 5.5.33
Retry finished in: 1.4841909408569
Output for 5.5.32
Retry finished in: 1.6891961097717
Output for 5.5.31
Retry finished in: 1.6817319393158
Output for 5.5.30
Retry finished in: 1.709321975708
Output for 5.5.29
Retry finished in: 1.6896231174469
Output for 5.5.28
Retry finished in: 1.6904249191284
Output for 5.5.27
Retry finished in: 1.6480479240417
Output for 5.5.26
Retry finished in: 1.680722951889
Output for 5.5.25
Retry finished in: 1.6481809616089
Output for 5.5.24
Retry finished in: 1.7284140586853
Output for 5.4.45
Retry finished in: 1.385913848877
Output for 5.4.44
Retry finished in: 1.3536489009857
Output for 5.4.43
Retry finished in: 1.9575970172882
Output for 5.4.42
Retry finished in: 1.3542339801788
Output for 5.4.41
Retry finished in: 1.4167878627777
Output for 5.4.40
Retry finished in: 1.3941309452057
Output for 5.4.39
Retry finished in: 1.3588528633118
Output for 5.4.38
Retry finished in: 1.4145359992981
Output for 5.4.37
Retry finished in: 1.3840148448944
Output for 5.4.36
Retry finished in: 1.2972860336304
Output for 5.4.35
Retry finished in: 1.4758858680725
Output for 5.4.34
Retry finished in: 1.3812119960785
Output for 5.4.32
Retry finished in: 1.3645040988922
Output for 5.4.31
Retry finished in: 1.3616290092468
Output for 5.4.30
Retry finished in: 1.5838661193848
Output for 5.4.29
Retry finished in: 1.3800749778748
Output for 5.4.28
Retry finished in: 1.383682012558
Output for 5.4.27
Retry finished in: 1.4047241210938
Output for 5.4.26
Retry finished in: 1.3833689689636
Output for 5.4.25
Retry finished in: 1.3876569271088
Output for 5.4.24
Retry finished in: 1.4226758480072
Output for 5.4.23
Retry finished in: 1.4185612201691
Output for 5.4.22
Retry finished in: 1.6491351127625
Output for 5.4.21
Retry finished in: 1.4038889408112
Output for 5.4.20
Retry finished in: 1.425479888916
Output for 5.4.19
Retry finished in: 1.3970170021057
Output for 5.4.18
Retry finished in: 1.4062240123749
Output for 5.4.17
Retry finished in: 1.3871221542358
Output for 5.4.16
Retry finished in: 1.3860199451447
Output for 5.4.15
Retry finished in: 1.3524699211121
Output for 5.4.14
Retry finished in: 1.7725129127502
Output for 5.4.13
Retry finished in: 1.386430978775
Output for 5.4.12
Retry finished in: 1.4853091239929
Output for 5.4.11
Retry finished in: 1.379289150238
Output for 5.4.10
Retry finished in: 1.3766920566559
Output for 5.4.9
Retry finished in: 1.3821089267731
Output for 5.4.8
Retry finished in: 1.37322306633
Output for 5.4.7
Retry finished in: 1.4125940799713
Output for 5.4.6
Retry finished in: 1.3949530124664
Output for 5.4.5
Retry finished in: 1.4044070243835
Output for 5.4.4
Retry finished in: 1.393385887146
Output for 5.4.3
Retry finished in: 1.413232088089
Output for 5.4.2
Retry finished in: 1.4002380371094
Output for 5.4.1
Retry finished in: 1.4589049816132
Output for 5.4.0
Retry finished in: 1.3593468666077
Output for 5.3.9 - 5.3.29
Catchable fatal error: Argument 2 passed to retry() must be an instance of callable, instance of Closure given, called in /in/BOQpu on line 31 and defined in /in/BOQpu on line 3
Process exited with code 255.