PHP Warning: strlen() expects parameter 1 to be string, array given in /vendor/workerman/workerman/Connection/TcpConnection.php on line 705
是否有改动mqtt client或者workemran源码?
/vendor/workerman/workerman/Connection/TcpConnection.php 704和705行之间加个代码
if (is_array($this->_sendBuffer)) { var_dump($this->_sendBuffer); }
打印下看下是什么数据。
另外发下能重现这个问题的业务代码。
问题在workerman/workerman/Connection/TcpConnection.php on line 705 if ($len === \strlen($send_buffer)) { $this->bytesWritten += $len; return true; } send_buffer是array,这个send_buffer来自workerman/mqtt/src/Client.php public function onConnectionConnect() { if ($this->_doNotReconnect) { $this->close(); return; } //['cmd'=>1, 'clean_session'=>x, 'will'=>['qos'=>x, 'retain'=>x, 'topic'=>x, 'content'=>x],'username'=>x, 'password'=>x, 'keepalive'=>x, 'protocol_name'=>x, 'protocol_level'=>x, 'client_id' => x] $package = array( 'cmd' => Mqtt::CMD_CONNECT, 'clean_session' => $this->_options['clean_session'], 'username' => $this->_options['username'], 'password' => $this->_options['password'], 'keepalive' => $this->_options['keepalive'], 'protocol_name' => $this->_options['protocol_name'], 'protocol_level' => $this->_options['protocol_level'], 'client_id' => $this->_options['client_id'], ); if (isset($this->_options['will'])) { $package['will'] = $this->_options['will']; } $this->_state = static::STATE_WAITCONACK; $this->_connection->send($package); 就是这个package。
$this->_sendBuffer 是Mqtt::encode后的数据,不会是数组,你看下是不是你改动了源码。
感谢,找到了。MQTT host 没有写协议名,Mqtt::encode返回还是array。加上mqtt://就好了
是否有改动mqtt client或者workemran源码?
/vendor/workerman/workerman/Connection/TcpConnection.php 704和705行之间加个代码
打印下看下是什么数据。
另外发下能重现这个问题的业务代码。
问题在workerman/workerman/Connection/TcpConnection.php on line 705
if ($len === \strlen($send_buffer)) {
$this->bytesWritten += $len;
return true;
}
send_buffer是array,这个send_buffer来自workerman/mqtt/src/Client.php
public function onConnectionConnect()
{
if ($this->_doNotReconnect) {
$this->close();
return;
}
//['cmd'=>1, 'clean_session'=>x, 'will'=>['qos'=>x, 'retain'=>x, 'topic'=>x, 'content'=>x],'username'=>x, 'password'=>x, 'keepalive'=>x, 'protocol_name'=>x, 'protocol_level'=>x, 'client_id' => x]
$package = array(
'cmd' => Mqtt::CMD_CONNECT,
'clean_session' => $this->_options['clean_session'],
'username' => $this->_options['username'],
'password' => $this->_options['password'],
'keepalive' => $this->_options['keepalive'],
'protocol_name' => $this->_options['protocol_name'],
'protocol_level' => $this->_options['protocol_level'],
'client_id' => $this->_options['client_id'],
);
if (isset($this->_options['will'])) {
$package['will'] = $this->_options['will'];
}
$this->_state = static::STATE_WAITCONACK;
$this->_connection->send($package);
就是这个package。
$this->_sendBuffer 是Mqtt::encode后的数据,不会是数组,你看下是不是你改动了源码。
感谢,找到了。MQTT host 没有写协议名,Mqtt::encode返回还是array。加上mqtt://就好了