After some experimenting trying to determine whether memcached is actually running it appears that the only way to do this is by creating a custom error handler to suppress the notice/warning thrown by Memcache::connect
I already have an error handler for my application that doesn't respond to this in a way that would suppress the error.
So if I have a method, say checkRunning()
like so:
public function checkRunning() {
$test = new Memcache;
return @$test->connect(CACHE_HOSTNAME, CACHE_PORT);
}
How can I apply a custom error handler to this method so that it just returns false, without overriding my existing error handler?
I'm guessing your error handler is simply not written correctly. Take particular note of this:
error_reporting()
settings will have no effect and your error handler will be called regardless - however you are still able to read the current value oferror_reporting
and act appropriately. Of particular note is that this value will be0
if the statement that caused the error was prepended by the@
error-control operator.
If your error handler obeyed the @
operator, your code should be fine.