Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

只能连本机的9092端口,连接远程会提示Could not connect to tcp://localhost:9092 #39

Closed
xilin693 opened this issue May 25, 2021 · 4 comments
Labels
question Further information is requested

Comments

@xilin693
Copy link

  • 你遇到了什么问题?

只能连本机的9092端口,连接远程会提示:Could not connect to tcp://localhost:9092 (Connection refused [111]) File:...../vendor/longlang/phpkafka/src/Socket/SwooleSocket.php Line:95
我的ip和端口号都不是localhost和9092,不知道为什么还是会连接到localhost:9092上

  • Kafka 环境是自建还是云服务?

自建,尝试使用华为云的kafka会报一个内存溢出的错误,所以先放弃了,华为云的提示为allowed memory size of 134... bytes exhausted... File:../longlang/phpkafka/src/Broker.php Line136

  • 请执行下面的命令获取环境信息。

php -v & php --ri swoole & composer info | grep longlang/phpkafka

# 粘贴到这里

[1] 22822
[2] 22823
PHP 7.3.27 (cli) (built: Apr 10 2021 14:10:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.27, Copyright (c) 1999-2018, by Zend Technologies

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.5
Built => Apr 20 2021 10:16:05
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
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
Composer could not find a composer.json file in /usr/src/app/example
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
[1]-  Done                    php -v
[2]+  Done                    php --ri swoole

* 提供最小可复现代码:

```php
        $config = new ProducerConfig();
        $config->setBootstrapServer(['124.xxx.xxx.xxx,9095']);
        $config->setUpdateBrokers(true);
        $config->setAcks(-1);
        $producer = new Producer($config);
        $topic = 'test333';
        $value = (string) microtime(true);
        $key = uniqid('', true);
        $producer->send($topic, $value, $key);

@Yurunsoft
Copy link
Member

longlang/phpkafka 版本是否最新?

如果有内存溢出,请提供完整调用堆栈。

localhost 问题和你的 kafka 配置有关

@xilin693
Copy link
Author

收到,谢谢,phpkafka是最新的.华为云的问题我作一个最纯粹的测试再发结果,目前在框架中运行,担心会受到框架的影响.

@xilin693
Copy link
Author

kafka的配置添加了listeners后不会报错了.华为云的Kafka连接还是有问题,简单修改了下broker.php136行的(临时取消array_merge作测试以确认问题),又报Protocol/Type/Int16.php 43行内存溢出(unpack(self::FORAMT, $value)[1]那段),待进一步确认.

@xilin693
Copy link
Author

华为云的phpkafka已确认可以正常使用,需要在华为云的Kafka实例中开启"自动创建topics"即可,这样就不会报内存溢出的错误了.

@Yurunsoft Yurunsoft added the question Further information is requested label Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants