Once you subscribe, you cannot leave #215

Closed
dattas opened this Issue Jul 18, 2012 · 0 comments

Comments

Projects
None yet
2 participants

dattas commented Jul 18, 2012

Unless you set a socket timeout, you cannot leave the subscribe loop. An easy fix is to have the user function that gets called return false if they want out of the loop. Here is a patch I created to resolve this on my own system (changed to match current master): I'd love to see this or something like it implemented.

--- a/redis.c
+++ b/redis.c
@@ -5417,7 +5417,11 @@ PHP_METHOD(Redis, subscribe)
                switch(callback_type) {
                        case R_SUB_CALLBACK_CLASS_TYPE:
                        MAKE_STD_ZVAL(z_ret);
                               call_user_function(&ce->function_table, &z_o, z_fun, z_ret, 3, z_args TSRMLS_CC);
+                               if(Z_TYPE_P(z_ret) == IS_BOOL && Z_BVAL_P(z_ret) == 0){
+                                       efree(z_ret);
+                                       RETURN_FALSE;
+                               }
                        efree(z_ret);
                                break;

@@ -5426,6 +5430,11 @@ PHP_METHOD(Redis, subscribe)
                                MAKE_STD_ZVAL(z_fun);
                                ZVAL_STRINGL(z_fun, callback_ft_name, callback_ft_name_len, 0);
                        call_user_function(EG(function_table), NULL, z_fun, z_ret, 3, z_args TSRMLS_CC);
+                               if(Z_TYPE_P(z_ret) == IS_BOOL && Z_BVAL_P(z_ret) == 0){
+                                       efree(z_fun);
+                                       efree(z_ret);
+                                       RETURN_FALSE;
+                               }
                        efree(z_fun);
                        efree(z_ret);
                                break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment