Last active
June 29, 2020 01:37
-
-
Save vitormattos/8fd1c827eb9705051e3c1d83aa95f1a7 to your computer and use it in GitHub Desktop.
Script to wait for db is receiving new connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
function dbIsUp() { | |
try { | |
$dsn = getenv('DB_TYPE').':dbname='.getenv('DB_NAME').';host='.getenv('DB_HOST'); | |
new PDO($dsn, getenv('DB_USER'), getenv('DB_PASSWD')); | |
} catch(Exception $e) { | |
echo $e->getMessage().PHP_EOL; | |
return false; | |
} | |
return true; | |
} | |
while(!dbIsUp()) { | |
sleep(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment