From c6e7b744c309f5862b4bffe0236c72b3b868fd90 Mon Sep 17 00:00:00 2001 From: Evan Darwin Date: Sat, 20 Jun 2015 13:03:09 -0700 Subject: [PATCH] Silently handle socket errors in the UdpAdapter (closes #27), add testcase Conflicts: tests/ClientTest.php --- src/Adapter/UdpAdapter.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Adapter/UdpAdapter.php b/src/Adapter/UdpAdapter.php index e497b13b7..2f9930087 100644 --- a/src/Adapter/UdpAdapter.php +++ b/src/Adapter/UdpAdapter.php @@ -15,9 +15,18 @@ final class UdpAdapter extends AdapterAbstract public function write($message) { + // Create a handler in order to handle the 'Host is down' message + set_error_handler(function() { + // Suppress the error, this is the UDP adapter and if we can't send + // it then we shouldn't inturrupt their application. + }); + $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_sendto($socket, $message, strlen($message), 0, $this->getOptions()->getHost(), $this->getOptions()->getPort()); socket_close($socket); + + // Remove our error handler. + restore_error_handler(); } private function serialize(array $message)