summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Dickmeiss <dickmeiss@php.net>2003-10-24 19:32:09 +0000
committerAdam Dickmeiss <dickmeiss@php.net>2003-10-24 19:32:09 +0000
commitdca01635d528451bdb8777203040ebf97e95598f (patch)
treefc9c2e9bc0003217eed2cb8403f1592c4c4a1560
parenteabcb173b1fc0926a2d33162749b89a67fea86ed (diff)
downloadphp-git-dca01635d528451bdb8777203040ebf97e95598f.tar.gz
For YAZ, RSHUTDOWN closes persistent connections that have been idle
more than yaz.keepalive seconds. Default value for config yaz.keepalive is 120 seconds. The shutdown prevents many sockets in CLOSE_WAIT state.
-rw-r--r--ext/yaz/php_yaz.c36
-rw-r--r--ext/yaz/php_yaz.h1
2 files changed, 35 insertions, 2 deletions
diff --git a/ext/yaz/php_yaz.c b/ext/yaz/php_yaz.c
index 23e1c0c12b..d69e123289 100644
--- a/ext/yaz/php_yaz.c
+++ b/ext/yaz/php_yaz.c
@@ -48,7 +48,7 @@
#include <yaz/yaz-ccl.h>
#include <yaz/zoom.h>
-#define MAX_ASSOC 100
+#define MAX_ASSOC 200
typedef struct Yaz_AssociationInfo *Yaz_Association;
@@ -63,6 +63,7 @@ struct Yaz_AssociationInfo {
int in_use;
int order;
int zval_resource;
+ long time_stamp;
};
static Yaz_Association yaz_association_mk()
@@ -81,6 +82,7 @@ static Yaz_Association yaz_association_mk()
p->persistent = 0;
p->ccl_parser = ccl_parser_create();
p->ccl_parser->bibset = 0;
+ p->time_stamp = 0;
return p;
}
@@ -374,7 +376,7 @@ PHP_FUNCTION(yaz_connect)
as->in_use = 1;
as->persistent = persistent;
as->order = YAZSG(assoc_seq);
-
+ as->time_stamp = time(0);
#ifdef ZTS
tsrm_mutex_unlock (yaz_mutex);
#endif
@@ -1484,6 +1486,11 @@ PHP_INI_BEGIN()
#else
STD_PHP_INI_ENTRY("yaz.max_links", "100", PHP_INI_ALL, OnUpdateInt, max_links, zend_yaz_globals, yaz_globals)
#endif
+#if PHP_MAJOR_VERSION >= 5
+ STD_PHP_INI_ENTRY("yaz.keepalive", "120", PHP_INI_ALL, OnUpdateLong, keepalive, zend_yaz_globals, yaz_globals)
+#else
+ STD_PHP_INI_ENTRY("yaz.keepalive", "120", PHP_INI_ALL, OnUpdateInt, keepalive, zend_yaz_globals, yaz_globals)
+#endif
STD_PHP_INI_ENTRY("yaz.log_file", NULL, PHP_INI_ALL, OnUpdateString, log_file, zend_yaz_globals, yaz_globals)
PHP_INI_END()
/* }}} */
@@ -1566,6 +1573,31 @@ PHP_MINFO_FUNCTION(yaz)
PHP_RSHUTDOWN_FUNCTION(yaz)
{
+ long now = time(0);
+ int i;
+
+ yaz_log(LOG_LOG, "rshutdown keepalive=%ld", YAZSG(keepalive));
+#ifdef ZTS
+ tsrm_mutex_lock(yaz_mutex);
+#endif
+ for (i = 0; i < YAZSG(max_links); i++) {
+ Yaz_Association *as = shared_associations + i;
+ if (*as)
+ {
+ if (now - (*as)->time_stamp > YAZSG(keepalive))
+ {
+ const char *host = option_get(*as, "host");
+ if (host)
+ yaz_log(LOG_LOG, "shutdown of %s", host);
+
+ yaz_association_destroy(*as);
+ *as = 0;
+ }
+ }
+ }
+#ifdef ZTS
+ tsrm_mutex_unlock(yaz_mutex);
+#endif
return SUCCESS;
}
diff --git a/ext/yaz/php_yaz.h b/ext/yaz/php_yaz.h
index 8a76de0a01..01189568aa 100644
--- a/ext/yaz/php_yaz.h
+++ b/ext/yaz/php_yaz.h
@@ -58,6 +58,7 @@ PHP_FUNCTION(yaz_get_option);
ZEND_BEGIN_MODULE_GLOBALS(yaz)
int assoc_seq;
long max_links;
+ long keepalive;
char *log_file;
ZEND_END_MODULE_GLOBALS(yaz)