@@ -103,6 +103,22 @@ void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id) {
103
103
zend_register_persistent_resource (ZSTR_VAL (id ), ZSTR_LEN (id ), ptr , le_id );
104
104
}
105
105
106
+ typedef struct {
107
+ php_stream * stream ;
108
+ redis_sock_status status ;
109
+} PoolEntry ;
110
+
111
+ static void
112
+ pool_entry_dtor (void * ptr )
113
+ {
114
+ if (ptr != NULL ) {
115
+ PoolEntry * pe = ptr ;
116
+ if (pe -> stream != NULL ) {
117
+ php_stream_pclose (pe -> stream );
118
+ }
119
+ }
120
+ }
121
+
106
122
static ConnectionPool *
107
123
redis_sock_get_connection_pool (RedisSock * redis_sock )
108
124
{
@@ -121,7 +137,7 @@ redis_sock_get_connection_pool(RedisSock *redis_sock)
121
137
122
138
/* Create the pool and store it in our persistent list */
123
139
pool = pecalloc (1 , sizeof (* pool ), 1 );
124
- zend_llist_init (& pool -> list , sizeof (php_stream * ), NULL , 1 );
140
+ zend_llist_init (& pool -> list , sizeof (PoolEntry ), pool_entry_dtor , 1 );
125
141
redis_register_persistent_resource (persistent_id , pool , le_redis_pconnect );
126
142
127
143
zend_string_release (persistent_id );
@@ -2975,7 +2991,7 @@ static int
2975
2991
redis_sock_check_liveness (RedisSock * redis_sock )
2976
2992
{
2977
2993
char id [64 ], inbuf [4096 ];
2978
- int idlen , auth ;
2994
+ int idlen , auth = 0 ;
2979
2995
smart_string cmd = {0 };
2980
2996
size_t len ;
2981
2997
@@ -2993,8 +3009,10 @@ redis_sock_check_liveness(RedisSock *redis_sock)
2993
3009
return SUCCESS ;
2994
3010
}
2995
3011
2996
- /* AUTH (if we need it) */
2997
- auth = redis_sock_append_auth (redis_sock , & cmd );
3012
+ if (redis_sock -> status != REDIS_SOCK_STATUS_READY ) {
3013
+ /* AUTH (if we need it) */
3014
+ auth = redis_sock_append_auth (redis_sock , & cmd );
3015
+ }
2998
3016
2999
3017
/* ECHO challenge/response */
3000
3018
idlen = redis_uniqid (id , sizeof (id ));
@@ -3105,7 +3123,12 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock)
3105
3123
if (INI_INT ("redis.pconnect.pooling_enabled" )) {
3106
3124
p = redis_sock_get_connection_pool (redis_sock );
3107
3125
if (zend_llist_count (& p -> list ) > 0 ) {
3108
- redis_sock -> stream = * (php_stream * * )zend_llist_get_last (& p -> list );
3126
+ PoolEntry * pe = zend_llist_get_last (& p -> list );
3127
+ redis_sock -> status = pe -> status ;
3128
+ /* Move pointer */
3129
+ redis_sock -> stream = pe -> stream ;
3130
+ pe -> stream = NULL ;
3131
+
3109
3132
zend_llist_remove_tail (& p -> list );
3110
3133
3111
3134
if (redis_sock_check_liveness (redis_sock ) == SUCCESS ) {
@@ -3237,7 +3260,8 @@ redis_sock_disconnect(RedisSock *redis_sock, int force, int is_reset_mode)
3237
3260
free_reply_callbacks (redis_sock );
3238
3261
if (p ) p -> nb_active -- ;
3239
3262
} else if (p ) {
3240
- zend_llist_prepend_element (& p -> list , & redis_sock -> stream );
3263
+ PoolEntry pe = { redis_sock -> stream , redis_sock -> status };
3264
+ zend_llist_prepend_element (& p -> list , & pe );
3241
3265
}
3242
3266
} else {
3243
3267
php_stream_close (redis_sock -> stream );
0 commit comments