Skip to content

Instantly share code, notes, and snippets.

@vitormattos
Last active June 29, 2020 01:37
Show Gist options
  • Save vitormattos/8fd1c827eb9705051e3c1d83aa95f1a7 to your computer and use it in GitHub Desktop.
Save vitormattos/8fd1c827eb9705051e3c1d83aa95f1a7 to your computer and use it in GitHub Desktop.
Script to wait for db is receiving new connections
#!/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