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( <socket> ) 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
This commit is contained in:
Antoine Musso 2012-07-13 18:20:00 +02:00
parent 59408ef8b5
commit fe6da52a11

View file

@ -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;
}
}