GatewayWorker在windows问题

hulang

问题描述

下载
https://github.com/walkor/workerman-chat
运行到我的项目中后
爆一大堆的thinkphp8的错误,这下我就不知道怎么改了。。

Active code page: 65001

D:\laragon\www\web_page\public>php gateway_register.php gateway_gateway.php gateway_businessworker.php
---------------------------------------------- WORKERMAN -----------------------------------------------
Workerman version:4.1.15          PHP version:8.2.19
----------------------------------------------- WORKERS ------------------------------------------------
worker                                          listen                              processes   status
Register                                        text://127.0.0.1:1236               1           [ok]

Fatal error: Uncaught ReflectionException: Class "app" does not exist in D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php:377
Stack trace:
#0 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php(377): ReflectionClass->__construct('app')
#1 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php(253): think\Container->invokeClass('app', Array)
#2 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Facade.php(47): think\Container->make('app', Array, false)
#3 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Facade.php(97): think\Facade::createFacade()
#4 D:\laragon\www\web_page\vendor\hulang\think-addons\src\helper.php(13): think\Facade::__callStatic('getRootPath', Array)
#5 [internal function]: {closure}('app')
#6 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php(377): ReflectionClass->__construct('app')
#7 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Container.php(253): think\Container->invokeClass('app', Array)
#8 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Facade.php(47): think\Container->make('app', Array, false)
#9 D:\laragon\www\web_page\vendor\topthink\framework\src\think\Facade.php(97): think\Facade::createFacade()
#10 D:\laragon\www\web_page\vendor\hulang\think-addons\src\helper.php(13): think\Facade::__callStatic('getRootPath', Array)
#11 [internal function]: {closure}('Protocols\\Text')
#12 D:\laragon\www\web_page\vendor\workerman\workerman\Worker.php(2426): class_exists('Protocols\\Text')
#13 D:\laragon\www\web_page\vendor\workerman\workerman\Worker.php(2351): Workerman\Worker->parseSocketAddress()
#14 D:\laragon\www\web_page\vendor\workerman\workerman\Worker.php(1486): Workerman\Worker->listen()
#15 D:\laragon\www\web_page\vendor\workerman\workerman\Worker.php(1405): Workerman\Worker::forkWorkersForWindows()
#16 D:\laragon\www\web_page\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()
#17 D:\laragon\www\web_page\public\gateway_register.php(19): Workerman\Worker::runAll()
#18 D:\laragon\www\web_page\public\gateway_register.php(11): loadRegister()
#19 {main}
517 1 0
1个回答

walkor 打赏

重新创建项目,里面不要有tp的东西

  • hulang 2024-05-31

    作者大佬啊,我项目是tp,你让我不要有tp的。。。我运行默认的那个可以

  • walkor 2024-05-31

    gateway_register.php 代码怎么写的?

  • hulang 2024-05-31

    gateway_register

    <?php
    
    use Workerman\Worker;
    use GatewayWorker\BusinessWorker;
    use GatewayWorker\Gateway;
    use GatewayWorker\Register;
    use app\common\http\GatewayWorkerEvents;
    
    require_once __DIR__ . '/../vendor/autoload.php';
    
    loadRegister();
    
    function loadRegister()
    {
        // register服务必须是text协议,监听地址请用内网ip或者127.0.0.1
        // 为了安全,register不能监听0.0.0.0,也就是register服务不能暴露给外网
        new Register('text://127.0.0.1:1236');
        // 运行worker
        Worker::runAll();
    }
    

    gateway_gateway

    <?php
    
    use Workerman\Worker;
    use GatewayWorker\BusinessWorker;
    use GatewayWorker\Gateway;
    use GatewayWorker\Register;
    use app\common\http\GatewayWorkerEvents;
    
    require_once __DIR__ . '/../vendor/autoload.php';
    
    loadGateway();
    
    function loadGateway()
    {
        // gateway 进程
        $gateway = new Gateway('Websocket://0.0.0.0:7878');
        // 设置名称,方便status时查看
        $gateway->name = 'ChatGateway';
        // 设置进程数,一般两个进程就足够
        $gateway->count = 2;
        // 分布式部署时请设置成内网ip(非127.0.0.1)
        $gateway->lanIp = '127.0.0.1';
        // 内部通讯起始端口。假如$gateway->count=2,起始端口为2300
        // 则一般会使用2300 2301 2个端口作为内部通讯端口
        $gateway->startPort = 2300;
        // 心跳间隔
        $gateway->pingInterval = 10;
        // 心跳数据
        $gateway->pingData = '{"type":"ping"}';
        // 服务注册地址
        $gateway->registerAddress = '127.0.0.1:1236';
        // 运行worker
        Worker::runAll();
    }
    

    gateway_businessworker

    <?php
    
    use Workerman\Worker;
    use GatewayWorker\BusinessWorker;
    use GatewayWorker\Gateway;
    use GatewayWorker\Register;
    use app\common\http\GatewayWorkerEvents;
    
    require_once __DIR__ . '/../vendor/autoload.php';
    
    loadBusinessWorker();
    
    function loadBusinessWorker()
    {
        // bussinessWorker 进程
        $worker = new BusinessWorker();
        // worker名称
        $worker->name = 'ChatBusinessWorker';
        // bussinessWorker进程数量
        $worker->count = 4;
        // 服务注册地址
        $worker->registerAddress = '127.0.0.1:1236';
        // 事件处理类,默认是 Event 类
        $worker->eventHandler = GatewayWorkerEvents::class;
        // 运行worker
        Worker::runAll();
    }
  • walkor 2024-05-31

    这样,你写个test.php

    <?php
    require_once __DIR__ . '/../vendor/autoload.php';
    var_export(class_exists('app'));

    运行 php test.php 看下是否报错

  • hulang 2024-05-31

    报错,还和上面一模一样,这下,咋整啊。。晕了额。。

  • walkor 2024-05-31

    这个要问下tp了,就拿test.php代码示例去问就行

  • walkor 2024-05-31

    这个不是workerman这边的问题

  • hulang 2024-05-31

    好的,大佬,我现在就去tp的github提问去

  • qianmoqingfeng 2024-08-15

    start.php倒数第二行 加行 (new think\App())->http;

×
🔝