From 12e2ebc2b5a899b404c11ae638cfea3351d9888e Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Tue, 20 Jul 2021 15:11:54 -0400 Subject: [PATCH] Define loop control vars outside loop --- app/http.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/http.php b/app/http.php index b85d6a051b..74bbd1b0c2 100644 --- a/app/http.php +++ b/app/http.php @@ -56,6 +56,9 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { go(function() use ($register, $app) { // wait for database to be ready $attempts = 0; + $max = 10; + $sleep = 1; + do { try { $attempts++; @@ -64,13 +67,13 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { break; // leave the do-while if successful } catch(\Exception $e) { Console::warning("Database not ready. Retrying connection ({$attempts})..."); - if ($attempts >= 10) { + if ($attempts >= $max) { throw new \Exception('Failed to connect to database: '. $e->getMessage()); } - sleep(1); + sleep($sleep); continue; } - } while ($attempts < 10); + } while ($attempts < $max); App::setResource('db', function () use (&$db) { return $db;