memcached: better error messaging
authorAntoine Musso <hashar@free.fr>
Fri, 13 Jul 2012 16:20:00 +0000 (18:20 +0200)
committerAntoine Musso <hashar@free.fr>
Wed, 1 Aug 2012 14:33:26 +0000 (16:33 +0200)
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( <socket> ) 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

index ec67a39..63778b7 100644 (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,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;
                        }
                }