pixelfed-container/wait-for-db.php

32 lines
629 B
PHP
Raw Normal View History

2020-05-30 12:46:57 +02:00
<?php
$conn = mysqli_connect(
getenv('DB_HOST'),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD'),
getenv('DB_DATABASE'),
getenv('DB_PORT')
);
$counter = 10;
2020-05-30 13:08:08 +02:00
$count = 1;
2020-05-30 12:46:57 +02:00
while (!$conn) {
echo("Waiting for Database... $count / $counter\n");
sleep(2);
$conn = mysqli_connect(
getenv('DB_HOST'),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD'),
getenv('DB_DATABASE'),
getenv('DB_PORT')
);
$count++;
if($count == $counter) {
echo("Database did not respond after $counter tries, giving up\n");
die(1);
}
}
echo "Database is up\n";
?>