1--TEST-- 2PostgreSQL non-blocking async connect 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)) { 16 die("pg_connect() error"); 17} elseif (pg_connection_status($db) === PGSQL_CONNECTION_BAD) { 18 die("pg_connect() error"); 19} elseif ($db_socket = pg_socket($db)) { 20 stream_set_blocking($db_socket, FALSE); 21} else { 22 die("pg_socket() error"); 23} 24 25while (TRUE) { 26 switch ($status = pg_connect_poll($db)) { 27 case PGSQL_POLLING_READING: 28 nb_is_readable($db_socket); 29 break; 30 case PGSQL_POLLING_WRITING: 31 nb_is_writable($db_socket); 32 break; 33 case PGSQL_POLLING_FAILED: 34 die("async connection failed"); 35 case PGSQL_POLLING_OK: 36 break 2; 37 default: 38 die("unknown poll status"); 39 } 40} 41assert(pg_connection_status($db) === PGSQL_CONNECTION_OK); 42echo "OK"; 43 44pg_close($db); 45 46?> 47--EXPECT-- 48OK 49