Bug #1870: New feature: support for pgsql listen/notify mechanism
| From: | bandit at freeside dot elte dot hu | Date: | Sun, 25 Jul 1999 23:57:18 +0000 |
| Subject: | Bug #1870: New feature: support for pgsql listen/notify mechanism | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-9147@lists.php.net to get a copy of this message | ||
From: bandit@freeside.elte.hu
Operating system: Linux
PHP version: 3.0.11
PHP Bug Type: PostgreSQL related
Bug description: New feature: support for pgsql listen/notify mechanism
diff -ur php-3.0.11/functions/pgsql.c php-3.0.11-ak/functions/pgsql.c
--- php-3.0.11/functions/pgsql.c Mon Jul 26 01:31:14 1999
+++ php-3.0.11-ak/functions/pgsql.c Mon Jul 26 01:31:25 1999
@@ -82,6 +82,8 @@
{"pg_loread", php3_pgsql_lo_read, NULL},
{"pg_lowrite", php3_pgsql_lo_write, NULL},
{"pg_loreadall", php3_pgsql_lo_readall, NULL},
+ {"pg_getnotify", php3_pgsql_getnotify, NULL},
+ {"pg_get_be_pid", php3_pgsql_get_be_pid, NULL},
{NULL, NULL, NULL}
};
@@ -1491,6 +1493,110 @@
}
/* }}} */
+/* {{{ proto int pg_getnotify([int connection,] int block)
+ Retrieve a notify if there is one - block if blocking requested and there are no notifies
readily available */
+void php3_pgsql_getnotify(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *block,*pgsql_link;
+ int id,type,fd;
+ PGconn *pgsql;
+ PGnotify *notify;
+ fd_set rset;
+
+ switch(ARG_COUNT(ht)) {
+ case 1:
+ if (getParameters(ht, 1, &block)==FAILURE) {
+ RETURN_FALSE;
+ }
+ id = php3_pgsql_module.default_link;
+ break;
+ case 2:
+ if (getParameters(ht, 2, &pgsql_link, &block)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_long(pgsql_link);
+ id = pgsql_link->value.lval;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ pgsql = (PGconn *) php3_list_find(id,&type);
+ if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
+ php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
+ RETURN_FALSE;
+ }
+
+ PQconsumeInput(pgsql);
+ notify=PQnotifies(pgsql);
+
+ convert_to_long(block);
+ if (!notify && block->value.lval) {
+
+ fd = PQsocket(pgsql);
+
+ FD_ZERO(&rset);
+ FD_SET(fd,&rset);
+
+ if ( select(fd+1,&rset,NULL,NULL,NULL) == -1 ) {
+ php3_error(E_WARNING,"select() returned an error: %s",strerror(errno));
+ RETURN_FALSE;
+ }
+
+ PQconsumeInput(pgsql);
+ notify=PQnotifies(pgsql);
+ }
+
+ if (notify) {
+
+ array_init(return_value);
+
+ add_assoc_string(return_value,"notifyname",notify->relname,1);
+ add_assoc_long(return_value,"pid",notify->be_pid);
+
+ free(notify);
+
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto int pg_get_be_pid([int connection,])
+ Get backend PID e.g. for comparing with PID in received notify */
+void php3_pgsql_get_be_pid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *pgsql_link;
+ int id,type;
+ PGconn *pgsql;
+
+ switch(ARG_COUNT(ht)) {
+ case 0:
+ id = php3_pgsql_module.default_link;
+ break;
+ case 1:
+ if (getParameters(ht, 1, &pgsql_link)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_long(pgsql_link);
+ id = pgsql_link->value.lval;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ pgsql = (PGconn *) php3_list_find(id,&type);
+ if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
+ php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
+ RETURN_FALSE;
+ }
+
+ RETURN_LONG(PQbackendPID(pgsql));
+
+}
+/* }}} */
/* {{{ proto void php3_info_pgsql(void)
Show info about the pgsql module */
Only in php-3.0.11-ak/functions/: pgsql.c.orig
diff -ur php-3.0.11/functions/php3_pgsql.h php-3.0.11-ak/functions/php3_pgsql.h
--- php-3.0.11/functions/php3_pgsql.h Sun Apr 25 03:29:22 1999
+++ php-3.0.11-ak/functions/php3_pgsql.h Mon Jul 26 01:01:46 1999
@@ -81,6 +81,8 @@
extern void php3_pgsql_lo_read(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pgsql_lo_write(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pgsql_lo_readall(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_pgsql_getnotify(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_pgsql_get_be_pid(INTERNAL_FUNCTION_PARAMETERS);
void php3_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
int php3_pgsql_get_default_link(INTERNAL_FUNCTION_PARAMETERS);