Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42817 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96025 invoked from network); 25 Jan 2009 00:06:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2009 00:06:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=chuck@visc.us; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=chuck@visc.us; sender-id=pass Received-SPF: pass (pb1.pair.com: domain visc.us designates 216.23.174.66 as permitted sender) X-PHP-List-Original-Sender: chuck@visc.us X-Host-Fingerprint: 216.23.174.66 mx.visc.us Linux 2.4/2.6 Received: from [216.23.174.66] ([216.23.174.66:40900] helo=visc.us) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/D4-55096-AECAB794 for ; Sat, 24 Jan 2009 19:06:03 -0500 Received: (qmail 7590 invoked from network); 25 Jan 2009 01:12:20 -0000 Received: from c66-235-10-200.sea2.cablespeed.com (HELO ?192.168.1.104?) (chuck@66.235.10.200) by visc.us with ESMTPA; 25 Jan 2009 01:12:19 -0000 Message-ID: <497BACB6.1070606@visc.us> Date: Sat, 24 Jan 2009 16:05:10 -0800 User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------040900090701040502020608" Subject: New function: pg_get_socket From: chuck@visc.us (Charles) --------------040900090701040502020608 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This is a patch for 5.2.x to return a select()-able variable for a given PostgreSQL connection. PG allows ASync queries, pg_send_query, and notifications, pg_get_notify. Currently (afaik), there is no way to add a PostgreSQL socket to the event notification array in used with stream_select(); usage: $db=pg_connect(...); $db_socket = pg_get_socket($db); pg_send_query("select 1,pg_sleep(3)"); stream_select($db_socket, ...); pg_get_result($db); feature was requested Jan 2005 on the pg_get_result page of the main English manual. -Charles --------------040900090701040502020608 Content-Type: text/plain; name="add_pg_get_socket.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="add_pg_get_socket.diff" diff -c pgsql_old/php_pgsql.h pgsql/php_pgsql.h *** pgsql_old/php_pgsql.h 2007-12-30 23:20:10.000000000 -0800 --- pgsql/php_pgsql.h 2009-01-23 12:26:02.000000000 -0800 *************** *** 129,134 **** --- 129,135 ---- /* async message functions */ PHP_FUNCTION(pg_get_notify); PHP_FUNCTION(pg_get_pid); + PHP_FUNCTION(pg_get_socket); /* error message functions */ PHP_FUNCTION(pg_result_error); #if HAVE_PQRESULTERRORFIELD diff -c pgsql_old/pgsql.c pgsql/pgsql.c *** pgsql_old/pgsql.c 2008-10-15 17:45:21.000000000 -0700 --- pgsql/pgsql.c 2009-01-23 12:28:03.000000000 -0800 *************** *** 164,169 **** --- 164,170 ---- /* async message function */ PHP_FE(pg_get_notify, NULL) PHP_FE(pg_get_pid, NULL) + PHP_FE(pg_get_socket, NULL) /* error message functions */ PHP_FE(pg_result_error, NULL) #if HAVE_PQRESULTERRORFIELD *************** *** 4405,4410 **** --- 4406,4441 ---- } /* }}} */ + /* {{{ proto resource pg_socket(resource connection) + return connection socket */ + PHP_FUNCTION(pg_get_socket) + { + zval **pgsql_link; + int id = -1; + PGconn *pgsql; + int fd; + php_stream *stream; + php_socket_t *sock; + if (zend_get_parameters_ex(1, &pgsql_link) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (pgsql_link == NULL && id == -1) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + + fd = PQsocket(pgsql); + + stream = php_stream_sock_open_from_socket(fd,NULL); + + if(stream == NULL) RETURN_FALSE; + + ZVAL_RESOURCE(return_value, php_stream_get_resource_id(stream)); + } + /* }}} */ + /* {{{ php_pgsql_meta_data * TODO: Add meta_data cache for better performance */ --------------040900090701040502020608--