Skip to content

Commit cef01da

Browse files
kobi97krowinski
authored andcommitted
fix sending more than 16MB (#45)
1 parent 180e3d6 commit cef01da

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/MySQLReplication/BinLog/BinLogSocketConnect.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,43 @@ public function getResponse($checkResponse = true)
8181
return '';
8282
}
8383
$dataLength = unpack('L', $header[0] . $header[1] . $header[2] . chr(0))[1];
84+
$isMaxDataLength = $dataLength === $this->binaryDataMaxLength;
8485

8586
$result = $this->socket->readFromSocket($dataLength);
8687
if (true === $checkResponse) {
87-
$this->isWriteSuccessful($result);
88+
$this->isWriteSuccessful($result, $isMaxDataLength);
89+
}
90+
91+
//https://dev.mysql.com/doc/internals/en/sending-more-than-16mbyte.html
92+
while ($isMaxDataLength) {
93+
$header = $this->socket->readFromSocket(4);
94+
if ('' === $header) {
95+
return $result;
96+
}
97+
$dataLength = unpack('L', $header[0] . $header[1] . $header[2] . chr(0))[1];
98+
$isMaxDataLength = $dataLength === $this->binaryDataMaxLength;
99+
100+
$next_result = $this->socket->readFromSocket($dataLength);
101+
if (true === $checkResponse) {
102+
$this->isWriteSuccessful($next_result, $isMaxDataLength);
103+
}
104+
$result .= $next_result;
88105
}
89106

90107
return $result;
91108
}
92109

93110
/**
94111
* @param string $data
112+
* @param bool $isMaxDataLength
113+
*
95114
* @throws BinLogException
96115
*/
97-
private function isWriteSuccessful($data)
116+
private function isWriteSuccessful($data, $isMaxDataLength = false)
98117
{
118+
if ($isMaxDataLength) {
119+
return;
120+
}
99121
$head = ord($data[0]);
100122
if (!in_array($head, $this->packageOkHeader, true)) {
101123
$errorCode = unpack('v', $data[1] . $data[2])[1];

0 commit comments

Comments
 (0)