1--TEST--
2PostgreSQL non-blocking async connect
3--SKIPIF--
4<?php
5include("skipif.inc");
6?>
7--FILE--
8<?php
9
10include('config.inc');
11include('nonblocking.inc');
12
13if (!$db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC)) {
14	die("pg_connect() error");
15} elseif (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
16	die("pg_connect() error");
17} elseif ($db_socket = pg_socket($db)) {
18	stream_set_blocking($db_socket, FALSE);
19} else {
20	die("pg_socket() error");
21}
22
23while (TRUE) {
24	switch ($status = pg_connect_poll($db)) {
25		case PGSQL_POLLING_READING:
26			if (nb_is_readable($db_socket)) { break 2; }
27			break;
28		case PGSQL_POLLING_WRITING:
29			if (nb_is_writable($db_socket)) { break 2; }
30			break;
31		case PGSQL_POLLING_FAILED:
32			die("async connection failed");
33		case PGSQL_POLLING_OK:
34			break 2;
35	}
36}
37assert(pg_connection_status($db) === PGSQL_CONNECTION_MADE);
38echo "OK";
39
40pg_close($db);
41
42?>
43--EXPECT--
44OK
45