From: Antoine Musso Date: Fri, 13 Jul 2012 16:20:00 +0000 (+0200) Subject: memcached: better error messaging X-Git-Tag: 1.31.0-rc.0~22958^2~1 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/?a=commitdiff_plain;h=fe6da52a11375c83d86f73bf4725d14acfbf4cbf;p=lhc%2Fweb%2Fwiklou.git 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 form. This patch add a new message when fgets( ) return false and attempt to get the remote peer address / port to append to the error message. Might help us find out which memcached server is wild. Change-Id: If918e824970aaa8231078e42fd28d31e8dd4e319 --- diff --git a/includes/objectcache/MemcachedClient.php b/includes/objectcache/MemcachedClient.php index ec67a3955f..eda57c0725 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,12 @@ class MWMemcached { } } else { - $this->_debugprint( "Error parsing memcached response\n" ); + $peer = $peerAddress = $peerPort = ''; + $gotPeer = socket_getpeername( $sock, $peerAddress, $peerPort ); + if( $gotPeer ) { + $peer = " from [$peerAddress:$peerPort"; + } + $this->_debugprint( "Error parsing memcached response{$peer}\n" ); return 0; } }