summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2002-10-17 07:58:46 +0000
committerYasuo Ohgaki <yohgaki@php.net>2002-10-17 07:58:46 +0000
commit601a507ad68d7a4997937dba0c21a3e2f7c53e6e (patch)
tree7e26e6052b53990e0383d8b7a85522278f034ede /ext
parent29d16f67f40dc79fbbcff0ee8bad2d1381924072 (diff)
downloadphp-git-601a507ad68d7a4997937dba0c21a3e2f7c53e6e.tar.gz
Added async message function - pg_get_notify()
Diffstat (limited to 'ext')
-rw-r--r--ext/pgsql/pgsql.c40
-rw-r--r--ext/pgsql/php_pgsql.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index cc79ce0ccd..e0bd78ae5f 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -114,6 +114,8 @@ function_entry pgsql_functions[] = {
PHP_FE(pg_field_type, NULL)
PHP_FE(pg_field_prtlen, NULL)
PHP_FE(pg_field_is_null,NULL)
+ /* async message function */
+ PHP_FE(pg_get_notify, NULL)
/* error message functions */
PHP_FE(pg_result_error, NULL)
PHP_FE(pg_last_error, NULL)
@@ -3005,6 +3007,44 @@ PHP_FUNCTION(pg_result_status)
}
/* }}} */
+
+/* {{{ proto resource pg_get_notify([resource connection[, result_type]])
+ Get asynchronous notification */
+PHP_FUNCTION(pg_get_notify)
+{
+ zval *pgsql_link;
+ int id = -1, result_type = PGSQL_ASSOC;
+ PGconn *pgsql;
+ PGresult *pgsql_result;
+ PGnotify *pgsql_notify;
+ pgsql_result_handle *pg_result;
+
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r|l",
+ &pgsql_link) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+
+ PQconsumeInput(pgsql);
+ pgsql_notify = PQnotifies(pgsql);
+ if (!pgsql_notify) {
+ /* no notify message */
+ RETURN_FALSE;
+ }
+ array_init(return_value);
+ if (result_type & (PGSQL_NUM|PGSQL_BOTH)) {
+ add_index_string(return_value, 0, pgsql_notify->relname, 1);
+ add_index_long(return_value, 1, pgsql_notify->be_pid);
+ }
+ if (result_type & (PGSQL_ASSOC|PGSQL_BOTH)) {
+ add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
+ add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
+ }
+}
+/* }}} */
+
+
/* {{{ php_pgsql_meta_data
* TODO: Add meta_data cache for better performance
*/
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index d035798fe5..5fef4ef781 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -97,6 +97,8 @@ PHP_FUNCTION(pg_field_size);
PHP_FUNCTION(pg_field_type);
PHP_FUNCTION(pg_field_prtlen);
PHP_FUNCTION(pg_field_is_null);
+/* async message functions */
+PHP_FUNCTION(pg_get_notify);
/* error message functions */
PHP_FUNCTION(pg_result_error);
PHP_FUNCTION(pg_last_error);