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			nb_is_readable($db_socket);
27			break;
28		case PGSQL_POLLING_WRITING:
29			nb_is_writable($db_socket);
30			break;
31		case PGSQL_POLLING_FAILED:
32			die("async connection failed");
33		case PGSQL_POLLING_OK:
34			break 2;
35		default:
36			die("unknown poll status");
37	}
38}
39assert(pg_connection_status($db) === PGSQL_CONNECTION_OK);
40echo "OK";
41
42pg_close($db);
43
44?>
45--EXPECT--
46OK
47