From 29480c3e77a4e7a1359cd9e66e32da7446d18bb6 Mon Sep 17 00:00:00 2001 From: Janez Troha Date: Mon, 26 Nov 2018 19:31:31 +0100 Subject: [PATCH] UDP Client: Support writing large reports (#9) If a report is larger than 65536 it will be rejected by kernel and PHP engine and never sent. With this, we ensure that the packet is always sent and that it has proper signaling (MSG_EOR or MSG_EOF). TLDR; Solves the following issue: ```PHP Warning: socket_sendto(): unable to write to socket [90]: Message too long``` --- src/Jaeger/UDPClient.php | 20 +++++++++++--------- tests/unit/Jaeger/UDPClientTest.php | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Jaeger/UDPClient.php b/src/Jaeger/UDPClient.php index edcf283..7ca95ff 100644 --- a/src/Jaeger/UDPClient.php +++ b/src/Jaeger/UDPClient.php @@ -86,17 +86,19 @@ public function emitBatch(Batch $batch) $client = new AgentClient(null, $protocol); $client->emitBatch($batch); - $data = $buffer->getBuffer(); try { - socket_sendto( - $socket, - $data, - strlen($data), - 0, - $this->host, - $this->port - ); + while ($buffer->available()) { + $data = $buffer->read(65507); // max size of DGRAM payload https://stackoverflow.com/a/38742429 + socket_sendto( + $socket, + $data, + strlen($data), + ( $buffer->available() ) ? MSG_EOR : MSG_EOF, + $this->host, + $this->port + ); + } } finally { socket_close($socket); } diff --git a/tests/unit/Jaeger/UDPClientTest.php b/tests/unit/Jaeger/UDPClientTest.php index cd90824..7f2b2eb 100644 --- a/tests/unit/Jaeger/UDPClientTest.php +++ b/tests/unit/Jaeger/UDPClientTest.php @@ -93,7 +93,7 @@ public function testUsesSockets() $resource, Argument::type('string'), Argument::type('int'), - 0, + 512, '1.1.1.1', 1234 )->willReturn(123)->shouldBeCalledTimes(1);