phpkafka
phpkafka copied to clipboard
Invalid length 352518912 given, it should be lesser than or equals to 5242880
- 你遇到了什么问题?
prod.ERROR: Invalid length 352518912 given, it should be lesser than or equals to 5242880 {"exception":"[object] (longlang\phpkafka\Exception\SocketException(code: 0): Invalid length 352518912 given, it should be lesser than or equals to 5242880 at /web/vendor/longlang/phpkafka/src/Socket/StreamSocket.php:173) [stacktrace]
-
Kafka 环境是自建还是云服务? 云
-
请执行下面的命令获取环境信息。
php -v & php --ri swoole & composer info | grep longlang/phpkafka
# 粘贴到这里
[1] 7531
[2] 7532
PHP 7.4.30 (cli) (built: Jul 12 2022 09:31:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
swoole
Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.4.26
Built => Jul 27 2022 03:11:37
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1n 15 Mar 2022
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
Do not run Composer as root/super user! See https://getcomposer.org/root for details
- 提供最小可复现代码:
// 你的代码
public function recv(int $length, ?float $timeout = null): string
{
if ($length > self::READ_MAX_LENGTH) {
throw new SocketException(sprintf('Invalid length %d given, it should be lesser than or equals to %d', $length, self::READ_MAX_LENGTH));
}
if (null === $timeout) {
$timeout = $this->config->getRecvTimeout();
}
$readable = $this->select([$this->socket], $timeout);
if (false === $readable) {
$this->close();
throw new SocketException(sprintf('Could not read %d bytes from stream (not readable)', $length));
}
if (0 === $readable) { // select timeout
$res = $this->getMetaData();
$this->close();
if (!empty($res['timed_out'])) {
throw new SocketException(sprintf('Timed out reading %d bytes from stream', $length));
}
throw new SocketException(sprintf('Could not read %d bytes from stream (not readable)', $length));
}
$remainingBytes = $length;
$data = $chunk = '';
while ($remainingBytes > 0) {
$chunk = fread($this->socket, $remainingBytes);
if (false === $chunk || 0 === \strlen($chunk)) {
// Zero bytes because of EOF?
if (feof($this->socket)) {
$this->close();
throw new SocketException(sprintf('Unexpected EOF while reading %d bytes from stream (no data)', $length));
}
// Otherwise wait for bytes
$readable = $this->select([$this->socket], $timeout);
if (1 !== $readable) {
$this->close();
throw new SocketException(sprintf('Timed out while reading %d bytes from stream, %d bytes are still needed', $length, $remainingBytes));
}
continue; // attempt another read
}
$data .= $chunk;
$remainingBytes -= \strlen($chunk);
}
return $data;
}
At least in my case, it means that the server is behind TLS.
You need at least to enable it, so the stream reads the server certificate (open
is a weird name, it should be enable
maybe)
$config->setSsl(['open'=>true]);
depending on your configuration, you might also need to add your client certificate in there