php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1870 New feature: support for pgsql listen/notify mechanism
Submitted: 1999-07-25 19:57 UTC Modified: 2002-06-16 08:35 UTC
From: bandit at freeside dot elte dot hu Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 3.0.11 OS: Linux
Private report: No CVE-ID: None
 [1999-07-25 19:57 UTC] bandit at freeside dot elte dot hu
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);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-16 08:35 UTC] sander@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately, PHP 3 is no longer supported. Please download
the latest version of PHP 4 from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC