Patch rrdcached-disconnect-support for rrd Bug #66088
Patch version 2013-11-13 13:11 UTC
Return to Bug #66088 |
Download this patch
Patch Revisions:
Developer: killing@multiplay.co.uk
--- rrd.c.orig 2013-09-03 07:52:39.000000000 +0000
+++ rrd.c 2013-11-13 12:15:09.626958747 +0000
@@ -24,13 +24,25 @@
#include "rrd_update.h"
#include "rrd_info.h"
+#ifndef RRDC_PERSISTENT_CONNECTIONS
+#define RRDC_PERSISTENT_CONNECTIONS 1
+#endif
+
+static zend_bool rrdc_persistent_connections = RRDC_PERSISTENT_CONNECTIONS;
+
+/* Compatibility with prior to php prior to 5.3 */
+#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)
+#define zend_parse_parameters_none() \
+ zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
+#endif
+
/* {{{ proto string rrd_error()
Get the error message set by the last rrd tool function call, this function
clear error buffer also.
*/
PHP_FUNCTION(rrd_error)
{
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
+ if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -297,6 +309,7 @@ PHP_FUNCTION(rrd_lastupdate)
add_assoc_zval(return_value, "data", zv_data_array);
}
}
+/* }}} */
/* {{{ proto array rrd_restore(string xmlFile, string rrdFile [, array options])
Restores an RRD file from a XML dump */
@@ -488,6 +501,35 @@ PHP_FUNCTION(rrd_version)
{
RETVAL_STRING(rrd_strversion(), 1);
}
+/* }}} */
+
+/* {{{ proto void rrdc_disconnect()
+ Close any outstanding connection
+*/
+PHP_FUNCTION(rrdc_disconnect)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ rrdc_disconnect();
+}
+/* }}}*/
+
+/* {{{ proto void rrdc_persistent_connections()
+ Enables / disables the default for rrdcached connections to persist across requests
+*/
+PHP_FUNCTION(rrdc_persistent_connections)
+{
+ zend_bool persist = 0;
+ zend_bool last_persist = rrdc_persistent_connections;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &persist) == FAILURE) {
+ return;
+ }
+ rrdc_persistent_connections = persist;
+ RETURN_BOOL(last_persist);
+}
+/* }}}*/
/* {{{ arguments */
ZEND_BEGIN_ARG_INFO(arginfo_rrd_fetch, 0)
@@ -544,9 +586,13 @@ ZEND_BEGIN_ARG_INFO(arginfo_rrd_update,
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_rrdc_persistent_connections, 0)
+ ZEND_ARG_INFO(0, enabled)
+ZEND_END_ARG_INFO()
/* }}} */
-/* {{{ */
+/* {{{ rrd_functions */
static zend_function_entry rrd_functions[] = {
PHP_FE(rrd_update, arginfo_rrd_update)
PHP_FE(rrd_create, arginfo_rrd_create)
@@ -561,6 +607,8 @@ static zend_function_entry rrd_functions
PHP_FE(rrd_tune, arginfo_rrd_tune)
PHP_FE(rrd_xport, arginfo_rrd_xport)
PHP_FE(rrd_version, arginfo_rrd_version)
+ PHP_FE(rrdc_disconnect, NULL)
+ PHP_FE(rrdc_persistent_connections, arginfo_rrdc_persistent_connections)
{NULL, NULL, NULL}
};
/* }}} */
@@ -590,15 +638,35 @@ static PHP_MINFO_FUNCTION(rrd)
}
/* }}} */
+/* {{{ PHP_MSHUTDOWN_FUNCTION */
+static PHP_MSHUTDOWN_FUNCTION(rrd)
+{
+ /* Ensure we close any connection to rrdcached */
+ rrdc_disconnect();
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_RSHUTDOWN_FUNCTION */
+static PHP_RSHUTDOWN_FUNCTION(rrd)
+{
+ if (!rrdc_persistent_connections) {
+ /* Ensure we close any connection to rrdcached */
+ rrdc_disconnect();
+ }
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ rrd module_entry */
zend_module_entry rrd_module_entry = {
STANDARD_MODULE_HEADER,
"rrd",
rrd_functions,
PHP_MINIT(rrd),
- NULL, /* PHP_MSHUTDOWN(rrd) */
+ PHP_MSHUTDOWN(rrd),
NULL, /* PHP_RINIT(rrd) */
- NULL, /* PHP_RSHUTDOWN(rrd) */
+ PHP_RSHUTDOWN(rrd),
PHP_MINFO(rrd),
PHP_RRD_VERSION,
STANDARD_MODULE_PROPERTIES
@@ -665,3 +733,7 @@ void rrd_args_free(rrd_args *args)
efree(args);
}
/* }}} */
+
+/*
+ * vim: noet sw=4 ts=8 fdm=marker
+ */
|