@@ -338,8 +338,9 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
338338{
339339
340340 char inbuf [1024 ];
341- char * resp ;
341+ char * resp = NULL ;
342342
343+ redis_check_eof (redis_sock TSRMLS_CC );
343344 php_stream_gets (redis_sock -> stream , inbuf , 1024 );
344345
345346 switch (inbuf [0 ]) {
@@ -385,6 +386,8 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes)
385386
386387 char * reply ;
387388
389+ redis_check_eof (redis_sock TSRMLS_CC );
390+
388391 if (bytes == -1 ) {
389392 return NULL ;
390393 } else {
@@ -415,6 +418,7 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
415418 char inbuf [1024 ], * response ;
416419 int response_len ;
417420
421+ redis_check_eof (redis_sock TSRMLS_CC );
418422 php_stream_gets (redis_sock -> stream , inbuf , 1024 );
419423
420424 if (inbuf [0 ] != '*' ) {
@@ -443,10 +447,22 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
443447 */
444448PHPAPI int redis_sock_write (RedisSock * redis_sock , char * cmd , size_t sz )
445449{
446- php_stream_write (redis_sock -> stream , cmd , sz );
450+ redis_check_eof (redis_sock TSRMLS_CC );
451+ return php_stream_write (redis_sock -> stream , cmd , sz );
452+
447453 return 0 ;
448454}
449455
456+
457+ PHPAPI void redis_check_eof (RedisSock * redis_sock TSRMLS_DC ) {
458+ int eof = php_stream_eof (redis_sock -> stream );
459+ while (eof ) {
460+ redis_sock -> stream = NULL ;
461+ redis_sock_connect (redis_sock TSRMLS_CC );
462+ eof = php_stream_eof (redis_sock -> stream );
463+ }
464+ }
465+
450466/**
451467 * redis_sock_get
452468 */
0 commit comments