File: wait_broker.php

package info (click to toggle)
php-amqplib 3.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,060 kB
  • sloc: php: 13,145; makefile: 77; sh: 27
file content (35 lines) | stat: -rw-r--r-- 861 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

use PhpAmqpLib\Connection\AMQPStreamConnection;

ini_set('display_errors', 1);
error_reporting(E_ALL);

require __DIR__ . '/bootstrap.php';

$exception = null;
$timeout = isset($argv[1]) ? (int)$argv[1] : 30;
$start = microtime(true);
$until = $start + $timeout;

do {
    try {
        $connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
        if ($connection->isConnected()) {
            echo 'Broker is ready to accept connections', PHP_EOL;
            die;
        }
    } catch (Exception $exception) {
        echo '.';
        sleep(1);
    }
} while ($until > time());

$end = microtime(true);
if ($until < $end) {
    echo PHP_EOL, sprintf('Broker wait timeout out after %.1f', $end - $start), PHP_EOL;
    if ($exception) {
        echo $exception->getCode(), ':', $exception->getMessage(), PHP_EOL;
    }
    exit(1);
}