Writing large string error
giuseppedevito opened this issue · 2 comments
giuseppedevito commented
I think there is a bug at line 1150 of MqttClient class:
Lines 1141 to 1171 in 0847abe
This will result in DataTransferException
event with messages over 100 KB (MQTT has a maximum allowed message size of 256 MB).
I solved the issue adding the method:
protected function writeChunks($fp, $string) {
$fwrite = 0;
for ($written = 0; $written < strlen($string); $written += $fwrite) {
$fwrite = @fwrite($fp, substr($string, $written));
if ($fwrite === false) {
return $written;
}
}
return $written;
}
and changing line 1150 to:
$result = $this->writeChunks($this->socket, $data);
With this update your code is working fine.
Namoshek commented
A detailed analysis and a possible solution regarding this issue can be found in #133.
giuseppedevito commented