3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RetryCatch { protected static $_currentRetries = 0; /** * Resets the retries counter * @return void */ public static function resetRetries() { static::$_currentRetries = 0; } /** * Emulates a try-catch-retry block for each element of a provided array. * At least two callback functions must be provided. The first one is applied * to each element of the array. If it throws an Exception, the second callback * is invoked and it tries to "fix" the error. This handler is called a maximum * of $maxRetries times, before throwing another Exception itself. * That's why the handleException callback must call resetRetries() in order * to reset the counter back to 0 retries. * * Obligations of the iterateCallback: * - It must accept the current element as a first argument * * Obligations of the handleExceptionCallback: * - It must accept the Exception object as a first argument * - It must accept the remaining array of objects as a second argument * - It must call RetryCatch::resetRetries() upon successful error handling * * EXAMPLE USAGE: * $arr = array( * 1, false, 2, 3 * ); * RetryCatch::retry($arr, 5, 'SomeClass::iterateMethod', 'SomeClass::handleException'); * * OR with the optional parameters, allowing the use of objects and/or * arbitrary callback parameterrs: * $foo = new Foo(); * RetryCatch::retry($arr, 5, 'bar', 'handle', array(1, 2, 3), array(1, 2, 3), $foo, $foo); * * @internal call resetRetries() if the handleCallback runs successfully * @param array $array * @param int $maxRetries * @param string $iterateCallback * @param string $handleCallback * @param array $iterateParams * @param array $handleParams * @param object $iterateCallbackObject * @param object $handleCallbackObject * @throws RetryCatchException */ public static function retry($array, $maxRetries, $iterateCallback, $handleCallback, $iterateParams = null, $handleParams = null, $iterateCallbackObject = null, $handleCallbackObject = null) { while (!empty($array)) { reset($array); $key = key($array); try { if (!is_object($iterateCallbackObject)) { if (is_array($iterateParams) && !empty($iterateParams)) { $useIterateParams = $iterateParams; array_unshift($useIterateParams, $array[$key]); call_user_func_array($iterateCallback, $useIterateParams); } else { call_user_func($iterateCallback, ($array[$key])); } } else { if (is_array($iterateParams) && !empty($iterateParams)) { $useIterateParams = $iterateParams; array_unshift($useIterateParams, $array[$key]); call_user_func_array(array($iterateCallbackObject, $iterateCallback), $useIterateParams); } else { $iterateCallbackObject->$iterateCallback($array[$key]); } } unset($array[$key]); } catch (Exception $e) { static::$_currentRetries++; if (static::$_currentRetries <= $maxRetries) { if (!is_object($handleCallbackObject)) { if (is_array($handleParams) && !empty($handleParams)) { $useHandleParams = $handleParams; array_unshift($useHandleParams, $e, $array); call_user_func_array($handleCallback, $useHandleParams); } else { call_user_func($handleCallback, $e, $array); } } else { if (is_array($handleParams) && !empty($handleParams)) { $useHandleParams = $handleParams; array_unshift($useHandleParams, $e, $array); call_user_func_array(array($handleCallbackObject, $handleCallback), $useHandleParams); } else { $handleCallbackObject->$handleCallback($e, $array); } } } else { throw new RetryCatchException('RetryCatch::maxRetries reached'); } } } } } class RetryCatchException extends 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.0110.00718.43
8.3.50.0120.00822.05
8.3.40.0070.00718.54
8.3.30.0110.01119.05
8.3.20.0050.00320.31
8.3.10.0000.00822.14
8.3.00.0080.00022.45
8.2.180.0110.01116.60
8.2.170.0030.01022.96
8.2.160.0070.00720.64
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0060.00926.16
8.2.120.0100.00019.23
8.2.110.0030.00622.25
8.2.100.0130.00019.45
8.2.90.0000.00819.09
8.2.80.0000.00817.97
8.2.70.0070.00317.38
8.2.60.0030.00517.80
8.2.50.0030.00618.07
8.2.40.0040.00418.09
8.2.30.0000.00717.85
8.2.20.0040.00417.39
8.2.10.0040.00417.42
8.2.00.0000.00817.61
8.1.280.0170.00325.92
8.1.270.0080.00022.16
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.96
8.1.230.0110.00019.16
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0100.00017.10
8.1.190.0080.00017.16
8.1.180.0080.00018.59
8.1.170.0000.00818.57
8.1.160.0000.00721.83
8.1.150.0050.00218.55
8.1.140.0000.00717.36
8.1.130.0070.00017.66
8.1.120.0050.00317.40
8.1.110.0040.00417.33
8.1.100.0070.00017.40
8.1.90.0000.00717.44
8.1.80.0030.00317.26
8.1.70.0030.00317.31
8.1.60.0080.00717.54
8.1.50.0050.00217.34
8.1.40.0080.00017.48
8.1.30.0040.00417.50
8.1.20.0040.00417.57
8.1.10.0000.00717.43
8.1.00.0030.00617.29
8.0.300.0040.00418.77
8.0.290.0000.00817.18
8.0.280.0070.00018.35
8.0.270.0040.00417.14
8.0.260.0000.00816.66
8.0.250.0070.00016.88
8.0.240.0070.00016.87
8.0.230.0030.00316.89
8.0.220.0000.00716.70
8.0.210.0030.00316.86
8.0.200.0070.00016.89
8.0.190.0050.00216.88
8.0.180.0040.00416.69
8.0.170.0070.00016.82
8.0.160.0040.00416.93
8.0.150.0000.00716.77
8.0.140.0050.00216.68
8.0.130.0000.00513.17
8.0.120.0060.00316.78
8.0.110.0040.00416.71
8.0.100.0040.00416.72
8.0.90.0000.00716.59
8.0.80.0040.01116.82
8.0.70.0000.00716.74
8.0.60.0070.00016.82
8.0.50.0040.00416.84
8.0.30.0080.01017.18
8.0.20.0110.00817.40
8.0.10.0050.00317.05
8.0.00.0080.00916.68
7.4.330.0000.00615.00
7.4.320.0040.00416.53
7.4.300.0060.00016.54
7.4.290.0040.00716.53
7.4.280.0100.00016.45
7.4.270.0030.00316.33
7.4.260.0030.00316.32
7.4.250.0080.00016.38
7.4.240.0020.00616.43
7.4.230.0000.00716.32
7.4.220.0090.00916.55
7.4.210.0070.00816.52
7.4.200.0040.00416.45
7.4.190.0000.00716.61
7.4.160.0040.01116.49
7.4.150.0090.00917.40
7.4.140.0090.00917.86
7.4.130.0180.00816.37
7.4.120.0100.00716.42
7.4.110.0040.01416.47
7.4.100.0150.00316.53
7.4.90.0200.00316.30
7.4.80.0070.01319.39
7.4.70.0030.01416.33
7.4.60.0070.01016.33
7.4.50.0000.00816.36
7.4.40.0060.00922.77
7.4.30.0170.00016.46
7.4.00.0100.00714.83
7.3.330.0050.00013.14
7.3.320.0050.00013.25
7.3.310.0000.00816.23
7.3.300.0050.00216.22
7.3.290.0070.01116.24
7.3.280.0090.00916.23
7.3.270.0110.00717.40
7.3.260.0030.01316.48
7.3.250.0050.01216.31
7.3.240.0080.01216.55
7.3.230.0080.00816.39
7.3.210.0120.00416.18
7.3.200.0070.01016.08
7.3.190.0090.00916.26
7.3.180.0060.01216.20
7.3.170.0140.00716.43
7.3.160.0070.01016.11
7.3.120.0040.01214.63
7.2.330.0120.00616.68
7.2.320.0070.01016.59
7.2.310.0070.01016.36
7.2.300.0170.00616.54
7.2.290.0130.00716.38
7.2.00.0140.00418.88
7.1.100.0040.01417.87
7.1.70.0040.00416.73
7.1.60.0040.00717.02
7.1.50.0000.01116.54
7.1.40.0060.00616.44
7.1.30.0040.00716.43
7.1.20.0000.01216.74
7.1.10.0000.00816.51
7.1.00.0030.00516.63
7.0.200.0030.00616.70
7.0.190.0040.00416.57
7.0.180.0040.00416.04
7.0.170.0040.00716.27
7.0.160.0040.00416.05
7.0.150.0040.00415.96
7.0.140.0000.00716.15
7.0.130.0000.00916.34
7.0.120.0040.00416.64
7.0.110.0080.00316.13
7.0.100.0000.00716.40
7.0.90.0050.00216.15
7.0.80.0050.00516.14
7.0.70.0000.00715.98
7.0.60.0060.00316.05
7.0.50.0030.00616.35
7.0.40.0000.01214.76
7.0.30.0070.00314.76
7.0.20.0000.00714.76
7.0.10.0000.00814.76
7.0.00.0000.01114.76
5.6.300.0030.04420.70
5.6.290.0070.03620.59
5.6.280.0000.04821.09
5.6.270.0000.04620.90
5.6.260.0000.05720.90
5.6.250.0140.03520.88
5.6.240.0070.04120.86
5.6.230.0070.03820.99
5.6.220.0160.03620.96
5.6.210.0100.03621.07
5.6.200.0000.04820.98
5.6.190.0070.04021.00
5.6.180.0160.02620.98
5.6.170.0000.04320.95
5.6.160.0100.06320.85
5.6.150.0030.05720.88
5.6.140.0000.07120.94
5.6.130.0130.05320.88
5.6.120.0060.04420.84
5.6.110.0030.04220.94
5.6.100.0070.05921.05
5.6.90.0130.07421.02
5.6.80.0060.03620.26
5.6.70.0030.04420.23
5.6.60.0030.05220.22
5.6.50.0060.05520.39
5.6.40.0100.07120.24
5.6.30.0040.08220.37
5.6.20.0000.05020.34
5.6.10.0090.03720.17
5.6.00.0040.04720.19
5.5.380.0060.03817.48
5.5.370.0030.04117.41
5.5.360.0030.04617.62
5.5.350.0000.04217.56
5.5.340.0070.04017.71
5.5.330.0000.04518.01
5.5.320.0030.04218.09
5.5.310.0030.04118.04
5.5.300.0060.07417.86
5.5.290.0030.04418.10
5.5.280.0070.04618.04
5.5.270.0000.06918.02
5.5.260.0070.05718.03
5.5.250.0070.06617.87
5.5.240.0100.03217.39
5.5.230.0030.04517.41
5.5.220.0060.04517.50
5.5.210.0030.05917.41
5.5.200.0030.08117.53
5.5.190.0030.03817.44
5.5.180.0000.06417.38
5.5.160.0070.05617.09
5.5.150.0000.04717.18
5.5.140.0030.08217.44
5.5.130.0070.04017.44
5.5.120.0000.04117.47
5.5.110.0000.04217.43
5.5.100.0070.04317.32
5.5.90.0030.07917.43
5.5.80.0000.04017.30
5.5.70.0030.04317.33
5.5.60.0060.05216.95
5.5.50.0060.04517.28
5.5.40.0060.06717.10
5.5.30.0000.04917.29
5.5.20.0030.07817.41
5.5.10.0070.06117.30
5.5.00.0030.06316.97
5.4.450.0000.04819.30
5.4.440.0000.05319.30
5.4.430.0000.05519.28
5.4.420.0030.05619.48
5.4.410.0030.04719.27
5.4.400.0000.04319.07
5.4.390.0070.04019.17
5.4.380.0000.08619.21
5.4.370.0060.04519.07
5.4.360.0100.07418.98
5.4.350.0060.03519.10
5.4.340.0030.05119.05
5.4.320.0000.04719.20
5.4.310.0000.04119.07
5.4.300.0030.05819.20
5.4.290.0090.03118.98
5.4.280.0030.04318.91
5.4.270.0030.03619.07
5.4.260.0030.06119.05
5.4.250.0090.06919.15
5.4.240.0100.05018.91
5.4.230.0090.03219.06
5.4.220.0030.07119.11
5.4.210.0000.06219.11
5.4.200.0070.08018.97
5.4.190.0000.04619.09
5.4.180.0070.03718.94
5.4.170.0100.04218.96
5.4.160.0070.04719.09
5.4.150.0100.04819.10
5.4.140.0030.04116.56
5.4.130.0000.03816.51
5.4.120.0030.03516.59
5.4.110.0060.03716.80
5.4.100.0070.03116.76
5.4.90.0070.05016.69
5.4.80.0100.07016.68
5.4.70.0030.04216.66
5.4.60.0070.04016.39
5.4.50.0000.07516.40
5.4.40.0060.05816.51
5.4.30.0030.03416.67
5.4.20.0060.05416.68
5.4.10.0000.03916.60
5.4.00.0100.05916.19
5.3.290.0040.04014.76
5.3.280.0070.04614.76
5.3.270.0000.05214.91
5.3.260.0040.04014.86
5.3.250.0030.07314.76
5.3.240.0000.04114.82
5.3.230.0000.04014.80
5.3.220.0000.04414.89
5.3.210.0070.03914.76
5.3.200.0000.04614.78
5.3.190.0070.07714.87
5.3.180.0090.03414.89
5.3.170.0120.03214.86
5.3.160.0030.03714.88
5.3.150.0070.07314.76
5.3.140.0100.03014.88
5.3.130.0040.03714.84
5.3.120.0030.04614.86
5.3.110.0100.05514.84
5.3.100.0060.03814.76
5.3.90.0030.03614.76
5.3.80.0060.03514.76
5.3.70.0030.03714.76
5.3.60.0000.06514.76
5.3.50.0000.03714.76
5.3.40.0100.04514.76
5.3.30.0070.06014.76
5.3.20.0070.04514.76
5.3.10.0070.05714.76
5.3.00.0070.08214.76

preferences:
45.18 ms | 401 KiB | 5 Q