6 * This script tries to connect to a database for a given interval
7 * Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
9 * Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
15 $timeout = (float)$argv[3];
18 $port = (int)$argv[2];
21 fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
25 fwrite(STDERR, 'Timeout must be greater than zero'."\n");
29 fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
32 $socketTimeout = (float)ini_get('default_socket_timeout');
33 if ($socketTimeout > $timeout) {
34 $socketTimeout = $timeout;
36 $stopTime = time() + $timeout;
38 $sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
39 if ($sock !== false) {
46 } while (time() < $stopTime);