mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
Using PQSocketPoll to poll on a connection's socket. Returns immediatly is there no event expected on read and write. Other than that, it is a thin wrapper on top of poll, thus reflecting its return value. close GH-14366
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
--TEST--
|
|
PostgreSQL poll on connection's socket
|
|
--EXTENSIONS--
|
|
pgsql
|
|
--SKIPIF--
|
|
<?php
|
|
include("inc/skipif.inc");
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
|
|
include('inc/config.inc');
|
|
include('inc/nonblocking.inc');
|
|
|
|
if (!($db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC))) die("pg_connect failed");
|
|
$socket = pg_socket($db);
|
|
$fp = fopen(__DIR__ . "/inc/config.inc", "r");
|
|
try {
|
|
pg_socket_poll($fp, 0, 0);
|
|
} catch (\TypeError $e) {
|
|
echo $e->getMessage() . PHP_EOL;
|
|
}
|
|
|
|
if (($topoll = pg_socket_poll($socket, 1, 1, 1)) === -1) die("pg_socket_poll failed");
|
|
stream_set_blocking($socket, false);
|
|
|
|
while (1) {
|
|
switch ($status = pg_connect_poll($db)) {
|
|
case PGSQL_POLLING_READING:
|
|
nb_is_writable($socket);
|
|
break;
|
|
case PGSQL_POLLING_WRITING:
|
|
nb_is_writable($socket);
|
|
break;
|
|
case PGSQL_POLLING_OK:
|
|
break 2;
|
|
default:
|
|
die("poll failed");
|
|
}
|
|
}
|
|
assert(pg_connection_status($db) === PGSQL_CONNECTION_OK);
|
|
echo "OK";
|
|
|
|
pg_close($db);
|
|
|
|
?>
|
|
--EXPECT--
|
|
pg_socket_poll(): Argument #1 ($socket) invalid resource socket
|
|
OK
|