summaryrefslogtreecommitdiff
path: root/ext/pgsql/tests/29nb_async_connect.phpt
blob: fc3868a26db76fd127c2671c5bdc2ae83d905e68 (plain)
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
36
37
38
39
40
41
42
43
44
--TEST--
PostgreSQL non-blocking async connect
--SKIPIF--
<?php
include("skipif.inc");
?>
--FILE--
<?php

include('config.inc');
include('nonblocking.inc');

if (!$db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC)) {
	die("pg_connect() error");
} elseif (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
	die("pg_connect() error");
} elseif ($db_socket = pg_socket($db)) {
	stream_set_blocking($db_socket, FALSE);
} else {
	die("pg_socket() error");
}

while (TRUE) {
	switch ($status = pg_connect_poll($db)) {
		case PGSQL_POLLING_READING:
			if (nb_is_readable($db_socket)) { break 2; }
			break;
		case PGSQL_POLLING_WRITING:
			if (nb_is_writable($db_socket)) { break 2; }
			break;
		case PGSQL_POLLING_FAILED:
			die("async connection failed");
		case PGSQL_POLLING_OK:
			break 2;
	}
}
assert(pg_connection_status($db) === PGSQL_CONNECTION_MADE);
echo "OK";

pg_close($db);

?>
--EXPECT--
OK