-
-
Save krakjoe/326eadc61bea38fdd6e6 to your computer and use it in GitHub Desktop.
phpredis.php7.pclose.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/library.c b/library.c | |
index b58870e..a341b27 100644 | |
--- a/library.c | |
+++ b/library.c | |
@@ -1683,6 +1683,32 @@ PHP_REDIS_API int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC) | |
return 0; | |
} | |
+/** | |
+ * redis_sock_disconnect | |
+ */ | |
+PHP_REDIS_API int redis_sock_pdisconnect(RedisSock *redis_sock TSRMLS_DC) | |
+{ | |
+ if (redis_sock == NULL) { | |
+ return 1; | |
+ } | |
+ | |
+ redis_sock->dbNumber = 0; | |
+ if (redis_sock->stream != NULL) { | |
+ redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED; | |
+ redis_sock->watching = 0; | |
+ | |
+ /* Stil valid? */ | |
+ if(redis_sock->stream && redis_sock->persistent) { | |
+ php_stream_pclose(redis_sock->stream); | |
+ } | |
+ redis_sock->stream = NULL; | |
+ | |
+ return 1; | |
+ } | |
+ | |
+ return 0; | |
+} | |
+ | |
PHP_REDIS_API void redis_send_discard(INTERNAL_FUNCTION_PARAMETERS, | |
RedisSock *redis_sock) | |
{ | |
diff --git a/library.h b/library.h | |
index c3a248c..bff11c2 100644 | |
--- a/library.h | |
+++ b/library.h | |
@@ -32,6 +32,7 @@ PHP_REDIS_API RedisSock* redis_sock_create(char *host, int host_len, unsigned sh | |
PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC); | |
PHP_REDIS_API int redis_sock_server_open(RedisSock *redis_sock, int force_connect TSRMLS_DC); | |
PHP_REDIS_API int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC); | |
+PHP_REDIS_API int redis_sock_pdisconnect(RedisSock *redis_sock TSRMLS_DC); | |
PHP_REDIS_API void redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab); | |
PHP_REDIS_API char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_DC); | |
PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *_z_tab, void *ctx); | |
diff --git a/php_redis.h b/php_redis.h | |
index b52fcee..1d3a9b8 100644 | |
--- a/php_redis.h | |
+++ b/php_redis.h | |
@@ -32,6 +32,7 @@ PHP_METHOD(Redis, __destruct); | |
PHP_METHOD(Redis, connect); | |
PHP_METHOD(Redis, pconnect); | |
PHP_METHOD(Redis, close); | |
+PHP_METHOD(Redis, pclose); | |
PHP_METHOD(Redis, ping); | |
PHP_METHOD(Redis, echo); | |
PHP_METHOD(Redis, get); | |
diff --git a/redis.c b/redis.c | |
index 3316bcf..7719b71 100644 | |
--- a/redis.c | |
+++ b/redis.c | |
@@ -108,6 +108,7 @@ static zend_function_entry redis_functions[] = { | |
PHP_ME(Redis, __destruct, NULL, ZEND_ACC_DTOR | ZEND_ACC_PUBLIC) | |
PHP_ME(Redis, connect, NULL, ZEND_ACC_PUBLIC) | |
PHP_ME(Redis, pconnect, NULL, ZEND_ACC_PUBLIC) | |
+ PHP_ME(Redis, pclose, NULL, ZEND_ACC_PUBLIC) | |
PHP_ME(Redis, close, NULL, ZEND_ACC_PUBLIC) | |
PHP_ME(Redis, ping, NULL, ZEND_ACC_PUBLIC) | |
PHP_ME(Redis, echo, NULL, ZEND_ACC_PUBLIC) | |
@@ -820,6 +821,30 @@ PHP_METHOD(Redis, close) | |
} | |
/* }}} */ | |
+/* {{{ proto boolean Redis::pclose() | |
+ */ | |
+PHP_METHOD(Redis, pclose) | |
+{ | |
+ zval *object; | |
+ RedisSock *redis_sock = NULL; | |
+ | |
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", | |
+ &object, redis_ce) == FAILURE) { | |
+ RETURN_FALSE; | |
+ } | |
+ | |
+ if (redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) { | |
+ RETURN_FALSE; | |
+ } | |
+ | |
+ if (redis_sock_pdisconnect(redis_sock TSRMLS_CC)) { | |
+ RETURN_TRUE; | |
+ } | |
+ | |
+ RETURN_FALSE; | |
+} | |
+/* }}} */ | |
+ | |
/* {{{ proto boolean Redis::set(string key, mixed val, long timeout, | |
* [array opt) */ | |
PHP_METHOD(Redis, set) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment