Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42838 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53688 invoked from network); 26 Jan 2009 00:14:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2009 00:14:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@beccati.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@beccati.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain beccati.com designates 213.92.90.60 as permitted sender) X-PHP-List-Original-Sender: php@beccati.com X-Host-Fingerprint: 213.92.90.60 ispeed-srv6.housing.tomato.it Received: from [213.92.90.60] ([213.92.90.60:62068] helo=mail.beccati.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/C0-55096-4500D794 for ; Sun, 25 Jan 2009 19:14:13 -0500 Received: (qmail 88985 invoked from network); 26 Jan 2009 01:14:09 +0100 Received: from unknown (HELO ?192.168.1.201?) (matteo@beccati.com@88.149.176.119) by mail.beccati.com with SMTP; 26 Jan 2009 00:14:09 -0000 Message-ID: <497D0018.7040201@beccati.com> Date: Mon, 26 Jan 2009 01:13:12 +0100 User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------030607000109020003080104" Subject: PDO::PgSQL Notify support From: php@beccati.com (Matteo Beccati) --------------030607000109020003080104 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Hi, the recent email about pg_get_socket reminded me that PDO:PgSQL doesn't have notify support. Here's a small patch and a phpt that add support for the LISTEN/NOTIFY mechanism using PDO. The PDO::pgsqlGetNotify method only returns an assoc array, but it could be easily modified to mimic the behaviour of pg_get_notify. The patch applies to PHP 5.2 HEAD. If you find it useful I can provide patches to PHP_5_3 or PHP_6. Cheers -- Matteo Beccati OpenX - http://www.openx.org --------------030607000109020003080104 Content-Type: text/plain; name="notify.phpt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="notify.phpt" --TEST-- PDO PgSQL Notifies --SKIPIF-- --FILE-- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pid = $db->pgsqlGetPid(); var_dump($pid > 0); var_dump($db->pgsqlGetNotify()); $db->exec("LISTEN notify_phpt"); var_dump($db->pgsqlGetNotify()); $db->exec("NOTIFY notify_phpt"); $notify = $db->pgsqlGetNotify(); var_dump($notify['message']); var_dump($notify['pid'] == $pid); ?> --EXPECT-- bool(true) bool(false) bool(false) string(11) "notify_phpt" bool(true) --------------030607000109020003080104 Content-Type: text/plain; name="pdo_pgsql_notify.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pdo_pgsql_notify.diff" Index: ext/pdo_pgsql/pgsql_driver.c =================================================================== RCS file: /repository/php-src/ext/pdo_pgsql/pgsql_driver.c,v retrieving revision 1.53.2.14.2.12 diff -u -r1.53.2.14.2.12 pgsql_driver.c --- ext/pdo_pgsql/pgsql_driver.c 31 Dec 2008 11:17:42 -0000 1.53.2.14.2.12 +++ ext/pdo_pgsql/pgsql_driver.c 26 Jan 2009 00:04:47 -0000 @@ -626,11 +626,56 @@ } /* }}} */ +/* {{{ proto mixed PDO::pgsqlGetNotify() + Get asyncronous notification */ +static PHP_METHOD(PDO, pgsqlGetNotify) +{ + pdo_dbh_t *dbh; + pdo_pgsql_db_handle *H; + PGnotify *pgsql_notify; + + dbh = zend_object_store_get_object(getThis() TSRMLS_CC); + PDO_CONSTRUCT_CHECK; + + H = (pdo_pgsql_db_handle *)dbh->driver_data; + + PQconsumeInput(H->server); + pgsql_notify = PQnotifies(H->server); + + if (!pgsql_notify) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_string(return_value, "message", pgsql_notify->relname, 1); + add_assoc_long(return_value, "pid", pgsql_notify->be_pid); + + PQfreemem(pgsql_notify); +} +/* }}} */ + +/* {{{ proto int PDO::pgsqlGetPid() + Get backend(server) pid */ +static PHP_METHOD(PDO, pgsqlGetPid) +{ + pdo_dbh_t *dbh; + pdo_pgsql_db_handle *H; + + dbh = zend_object_store_get_object(getThis() TSRMLS_CC); + PDO_CONSTRUCT_CHECK; + + H = (pdo_pgsql_db_handle *)dbh->driver_data; + + RETURN_LONG(PQbackendPID(H->server)); +} +/* }}} */ static zend_function_entry dbh_methods[] = { PHP_ME(PDO, pgsqlLOBCreate, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDO, pgsqlLOBOpen, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDO, pgsqlLOBUnlink, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PDO, pgsqlGetNotify, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PDO, pgsqlGetPid, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; --------------030607000109020003080104--