thinkphp6 阿里云 stream_socket_client(): unable to

w5w4

问题描述

之前部署过好几个gatewayworker + thinkphp+ 第一次出现这种问题
1. (我只是一台服务器 没做分布式)
2. 第一次用阿里云服务器搭建
thinkphp bindUid的时候就提示
stream_socket_client(): unable to connect to tcp://127.0.0.1:29** (Connection refused)
php start.php status
php start.php start
php start.php start -d 都没问题
直接通过webscket聊天也没问题
但是通过GatewayClient\Gateway就报错 大佬们遇到过吗

start_register.php:

<?php 
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
use \Workerman\Worker;
use \GatewayWorker\Register;

// 自动加载类
require_once __DIR__ . '/../../vendor/autoload.php';

// register 必须是text协议
$register = new Register('text://0.0.0.0:1238');

// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

thinkphp

<?php

namespace app\api\controller;

use app\api\service\file\UploadService;
use app\api\service\user\UserLogService;
use app\api\service\user\UserService;
use GatewayClient\Gateway;
use think\facade\Request;

class User extends Base
{
    public function bind()
    {
        Gateway::$registerAddress = "127.0.0.1:1238";
        Gateway::sendToAll("11111"); //这里不会报错但是没发送成功
        Gateway::bindUid(Request::param('client_id'), 1);
        return msg(Request::param('client_id'));
    }
}
971 4 0
4个回答

Gin

Gateway::$registerAddress = "127.0.0.1:1238"; 127.0.0.1 换成服务器的内网地址 试试

  • w5w4 2023-03-29

    还是不行 换了局域网IP 还是提示 unable to connect to tcp://127.0.0.1:2918 (Connection refused)

  • Gin 2023-03-29

    确定 gatewayworker 是启动着的?

  • w5w4 2023-03-29

    是的
    php start.php status 正常的
    php start.php start 控制台没报错
    php start.php start -d 都没问题
    websocket也没问题正常使用

  • yongdao35 2023-03-29

    client_id 里包含了一些ip及端口信息,如果client_id是错的,就会有这个问题

yongdao35

https://www.workerman.net/doc/gateway-worker/work-with-other-frameworks.html#%E5%85%B3%E4%BA%8EGatewayClient

手册说如果GatewayClient和GatewayWorker不是在同一台服务器上,则需要先将start_gateway.php中的lanIp改成当前服务器的内网ip。看看是不是这个问题

  • w5w4 2023-03-29

    我在一台服务器。。 而且我改成了内网ip也不行

  • w5w4 2023-03-29

    谢谢 我刚才测试了 真有可能是 client_id的问题 我Android studio 那边返回的ID格式是 7f0000010b6600040ae3 就会报错
    但是我用其他方式返回的ID格式是 ac13c7ce0fa000000002 就不会报错
    应该是这个原因 我再看看 感谢你

w5w4

刚刚换成局域网IP  也不行

w5w4

占用大家的网络资源和时间非常抱歉
这个就是client_id 不存在导致的

导致这样的原因是。。。。
服务器太多了 Android Studio填错ws IP了 = =

年代过于久远,无法发表回答
🔝