From bbf703c4faeee306c3217d4354846f104275ba29 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 13 Jul 2012 18:20:00 +0200 Subject: [PATCH] memcached: better error messaging MemcachedClient output a generic error message: "Error parsing memcached response\n" whenever it is not able to read from the socket. It is also lacking the remote peer it is reading from. This patch add a new message when fgets( ) return false, which means we could not read from the file pointer. It also get the stream remote name for debugging purposes. Change-Id: I9b8a25a03af0d730aa3b4830a44b1ea739343274 --- includes/objectcache/MemcachedClient.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/objectcache/MemcachedClient.php b/includes/objectcache/MemcachedClient.php index ec67a3955f..63778b7988 100644 --- a/includes/objectcache/MemcachedClient.php +++ b/includes/objectcache/MemcachedClient.php @@ -895,7 +895,10 @@ class MWMemcached { function _load_items( $sock, &$ret ) { while ( 1 ) { $decl = fgets( $sock ); - if ( $decl == "END\r\n" ) { + if( $decl === false ) { + $this->_debugprint( "Error reading socket for a memcached response\n" ); + return 0; + } elseif ( $decl == "END\r\n" ) { return true; } elseif ( preg_match( '/^VALUE (\S+) (\d+) (\d+)\r\n$/', $decl, $match ) ) { list( $rkey, $flags, $len ) = array( $match[1], $match[2], $match[3] ); @@ -939,7 +942,8 @@ class MWMemcached { } } else { - $this->_debugprint( "Error parsing memcached response\n" ); + $peer = stream_socket_get_name( $sock, true /** remote **/ ); + $this->_debugprint( "Error parsing memcached response from [{$peer}]\n" ); return 0; } } -- 2.20.1