0

I am using memcache in PHP but I am struggeling how to handle the error it throws at me.

I use the addServer method to add servers but while still in production I sometimes don't have it turned on and the connection obviously can't be established. This is all expected but instead of an exception I get a notice I can't get ride off.

Notice: MemcachePool::set(): Server 192.168.1.2 (tcp 11211, udp 0) failed with: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)

How can I catch/handle this notice/error?

3
  • you can set the error_reporting level to turn off notices. you can prefix the statement with @
    – DevZer0
    Jul 12, 2013 at 11:55
  • try { $this->cache = Cache::instance(); } catch (Kohana_Exception $e) { Kohana::config_set('cache.default.driver', 'file'); $this->cache = Cache::instance(); }
    – Gunr Jesra
    Jul 12, 2013 at 11:55

1 Answer 1

0

You could either use a custom error handler so you can catch the notice when it happens and handle it appropriately, or check if the connection works after you execute addServer() and handle the failed connection there. For this check out this comment in the docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.