xref: /PHP-8.4/ext/pgsql/tests/pg_socket_poll.phpt (revision e69bccd7)
1--TEST--
2PostgreSQL poll on connection's socket
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("inc/skipif.inc");
8?>
9--FILE--
10<?php
11
12include('inc/config.inc');
13include('inc/nonblocking.inc');
14
15if (!($db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC))) die("pg_connect failed");
16$socket = pg_socket($db);
17$fp = fopen(__DIR__ . "/inc/config.inc", "r");
18try {
19	pg_socket_poll($fp, 0, 0);
20} catch (\TypeError $e) {
21	echo $e->getMessage() . PHP_EOL;
22}
23
24if (($topoll = pg_socket_poll($socket, 1, 1, 1)) === -1) die("pg_socket_poll failed");
25stream_set_blocking($socket, false);
26
27while (1) {
28    switch ($status = pg_connect_poll($db)) {
29        case PGSQL_POLLING_READING:
30            nb_is_writable($socket);
31            break;
32        case PGSQL_POLLING_WRITING:
33            nb_is_writable($socket);
34            break;
35        case PGSQL_POLLING_OK:
36            break 2;
37        default:
38            die("poll failed");
39    }
40}
41assert(pg_connection_status($db) === PGSQL_CONNECTION_OK);
42echo "OK";
43
44pg_close($db);
45
46?>
47--EXPECT--
48pg_socket_poll(): Argument #1 ($socket) invalid resource socket
49OK
50