Parcourir la source

Add custom timeout to healthchecks API

The default PHP timeout is 30 seconds. The default timeout for request.php is 10 seconds. If you have too many items set or connection takes longer than usual, healthchecks/run will return a 500 error. I propose using set_time_limit to temporarily override the timeout with a total amount of seconds calculated based on number of items in $allItems array multiples by 20 (to account for internal and external).
Jesse Hickman il y a 5 ans
Parent
commit
04a509785c
1 fichiers modifiés avec 6 ajouts et 1 suppressions
  1. 6 1
      api/plugins/healthChecks.php

+ 6 - 1
api/plugins/healthChecks.php

@@ -136,6 +136,11 @@ class HealthChecks extends Organizr
 					unset($allItems[$k]);
 				}
 			}
+			$limit = 30;
+			if (count($allItems) > 0){
+				$limit = count($allItems) * 20;
+			}
+			set_time_limit($limit);
 			foreach ($allItems as $k => $v) {
 				$testLocal = $v['Internal URL'] !== '' ?? false;
 				$testExternal = $v['External URL'] !== '' ?? false;
@@ -171,4 +176,4 @@ class HealthChecks extends Organizr
 			$this->setAPIResponse('error', 'User does not have access', 401);
 		}
 	}
-}
+}