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

Commit 29480c3

Browse files
dz0nychingor13
authored andcommitted
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```
1 parent 8d5ba4e commit 29480c3

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Jaeger/UDPClient.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,19 @@ public function emitBatch(Batch $batch)
8686
$client = new AgentClient(null, $protocol);
8787

8888
$client->emitBatch($batch);
89-
$data = $buffer->getBuffer();
9089

9190
try {
92-
socket_sendto(
93-
$socket,
94-
$data,
95-
strlen($data),
96-
0,
97-
$this->host,
98-
$this->port
99-
);
91+
while ($buffer->available()) {
92+
$data = $buffer->read(65507); // max size of DGRAM payload https://stackoverflow.com/a/38742429
93+
socket_sendto(
94+
$socket,
95+
$data,
96+
strlen($data),
97+
( $buffer->available() ) ? MSG_EOR : MSG_EOF,
98+
$this->host,
99+
$this->port
100+
);
101+
}
100102
} finally {
101103
socket_close($socket);
102104
}

tests/unit/Jaeger/UDPClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testUsesSockets()
9393
$resource,
9494
Argument::type('string'),
9595
Argument::type('int'),
96-
0,
96+
512,
9797
'1.1.1.1',
9898
1234
9999
)->willReturn(123)->shouldBeCalledTimes(1);

0 commit comments

Comments
 (0)