Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0267ad8

Browse files
committed
Merge branch 'master' of https://github.com/Savar/phpredis
2 parents 39f3107 + c5247be commit 0267ad8

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

library.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
2121
while(eof) {
2222
if(count++ == 10) { /* too many failures */
2323
if(redis_sock->stream) { /* close stream if still here */
24+
if (!redis_sock->persistent) { /* never ever close persistent streams by ourself */
2425
php_stream_close(redis_sock->stream);
26+
}
2527
redis_sock->stream = NULL;
28+
redis_sock->mode = ATOMIC;
2629
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
2730
}
2831
zend_throw_exception(redis_exception_ce, "Connection lost", 0 TSRMLS_CC);
2932
return -1;
3033
}
3134
if(redis_sock->stream) { /* close existing stream before reconnecting */
32-
php_stream_close(redis_sock->stream);
35+
if (!redis_sock->persistent) {
36+
php_stream_close(redis_sock->stream);
37+
}
3338
redis_sock->stream = NULL;
39+
redis_sock->mode = ATOMIC;
3440
}
3541
redis_sock_connect(redis_sock TSRMLS_CC); /* reconnect */
3642
if(redis_sock->stream) { /* check for EOF again. */
@@ -48,7 +54,9 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
4854
}
4955

5056
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
51-
php_stream_close(redis_sock->stream);
57+
if (!redis_sock->persistent) {
58+
php_stream_close(redis_sock->stream);
59+
}
5260
redis_sock->stream = NULL;
5361
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
5462
redis_sock->mode = ATOMIC;
@@ -118,7 +126,9 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
118126
}
119127

120128
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
121-
php_stream_close(redis_sock->stream);
129+
if (!redis_sock->persistent) {
130+
php_stream_close(redis_sock->stream);
131+
}
122132
redis_sock->stream = NULL;
123133
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
124134
redis_sock->mode = ATOMIC;
@@ -599,7 +609,9 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
599609
return -1;
600610
}
601611
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
602-
php_stream_close(redis_sock->stream);
612+
if (!redis_sock->persistent) {
613+
php_stream_close(redis_sock->stream);
614+
}
603615
redis_sock->stream = NULL;
604616
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
605617
redis_sock->mode = ATOMIC;
@@ -852,7 +864,9 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
852864
return -1;
853865
}
854866
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
855-
php_stream_close(redis_sock->stream);
867+
if (!redis_sock->persistent) {
868+
php_stream_close(redis_sock->stream);
869+
}
856870
redis_sock->stream = NULL;
857871
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
858872
redis_sock->mode = ATOMIC;
@@ -914,7 +928,9 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
914928
return -1;
915929
}
916930
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
917-
php_stream_close(redis_sock->stream);
931+
if (!redis_sock->persistent) {
932+
php_stream_close(redis_sock->stream);
933+
}
918934
redis_sock->stream = NULL;
919935
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
920936
redis_sock->mode = ATOMIC;
@@ -976,3 +992,5 @@ PHPAPI void redis_free_socket(RedisSock *redis_sock)
976992
efree(redis_sock);
977993
}
978994

995+
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
996+

0 commit comments

Comments
 (0)