<?php
$dbs = $ids = [];
for ($i = 1; $i <= 3; $i++) {
$dbs[$i] = new mysqli("db_host_$i", $user, $pass, "users");
}
foreach($dbs as $db) {
$result = $db->query("SELECT id from users where age > 21");
while($row = mysqli_fetch_assoc($result)) {
$ids[] = $row['id'];
}
}
<?php
$dbs = $ids = [];
for ($i = 1; $i <= 3; $i++) {
$dbs[$i] = new mysqli("db_host_$i", $user, $pass, "users");
}
foreach($dbs as $db) {
$result = $db->query("SELECT id from users where age > 21", MYSQLI_ASYNC);
}
$all_dbs = $read = $err = $rej = $dbs;
do {
if (!mysqli_poll($read, $err, $rej, 1)) {
continue;
}
foreach($all_dbs as $id => $db) {
if ($result = mysqli_reap_async_query($db)) {
while($row = mysqli_fetch_assoc($result)) {
$ids[] = $row['id'];
}
mysqli_free_result($result);
unset($all_dbs[$id]);
}
}
} while (count($all_dbs) > 0);