pdo; $results = []; $STH = $pdo->query("SELECT `host`, `base32` FROM `hosts`"); $hosts = $STH->fetchAll(PDO::FETCH_KEY_PAIR); /* Start temporary BOB tunnel for checking */ $bob = new BOB($options); $bob->setnick(); $bob->options(); $bob->newkeys(); $bob->intun(); $bob->start(); /* Sleep 10 seconds awaitng tunnels get built */ echo "BOB session started, awaiting 10 seconds for tunnels" . PHP_EOL; sleep(10); /* Start async checker tasks */ Loop::run(function () use (&$results, $hosts, $options) { $pool = new DefaultPool(64); $coroutines = []; foreach ($hosts as $host => $base32) { $coroutines[$host] = Amp\call(function () use ($pool, $base32, $options) { $result = yield $pool->enqueue(new App\Checker($base32, $options)); return $result; }); } $results = yield Amp\Promise\all($coroutines); return yield $pool->shutdown(); }); /* Stop BOB tunnel and terminate */ $bob->stop(); $bob->clear(); $bob = null; /* Update last seen time in DB */ $i = 0; $pdo->beginTransaction(); foreach ($results as $host => $result) { if($result) { $pdo->exec("UPDATE `hosts` SET `last_seen` = current_timestamp() WHERE `host` = '" . $host . "'"); $i++; } } $pdo->commit(); echo "Result: Total hosts: " . count($results) . ", Alive: " . $i . PHP_EOL;