File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,12 +128,20 @@ public function initialize()
128128 $ this ->memcached ->setOption (\Memcached::OPT_BINARY_PROTOCOL , true );
129129 }
130130
131- // TODO: check if we can connect to the server
132-
133131 // Add server
134132 $ this ->memcached ->addServer (
135133 $ this ->config ['host ' ], $ this ->config ['port ' ], $ this ->config ['weight ' ]
136134 );
135+
136+ // attempt to get status of servers
137+ $ stats = $ this ->memcached ->getStats ();
138+
139+ // $stats should be an associate array with a key in the format of host:port.
140+ // If it doesn't have the key, we know the server is not working as expected.
141+ if ( !isset ($ stats [$ this ->config ['host ' ]. ': ' .$ this ->config ['port ' ]]) )
142+ {
143+ throw new CriticalError ('Cache: Memcached connection failed. ' );
144+ }
137145 }
138146 elseif (class_exists ('\Memcache ' ))
139147 {
You can’t perform that action at this time.
0 commit comments