Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
UDP Client: Support writing large reports (#9)
Browse files Browse the repository at this point in the history
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```
  • Loading branch information
dz0ny authored and chingor13 committed Nov 26, 2018
1 parent 8d5ba4e commit 29480c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/Jaeger/UDPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Jaeger/UDPClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 29480c3

Please sign in to comment.