偶尔出现Call to undefined method getRealIp()

沉梦

问题描述

偶尔会出现Call to undefined method Workerman\Protocols\Http\Request::getRealIp() ,在刚启动时概率很高,要多刷新几次后网站访问才会正常,我搜索了类似的帖子有一个,按照老大提供的方法改了还是会出现
如下类似帖子
https://www.workerman.net/q/13952

我在Http.php添加onMessage回调打印

public function onMessage($connection, $request)
    {
        var_dump(get_class($request));
        parent::onMessage($connection, $request);
    }

出现报错时的类是Workerman\Protocols\Http\Request
截图

访问正常的类是support\Request
截图

我发现访问当出现报错的页面时,换一个url页面访问它又正常了,返回之前的报错页面的刷新很多次还是会报错,

程序代码

config/process.php

<?php
use app\process\Http;
use support\Log;
use support\Request;

global $argv;

$mode = config('app.mode', 'main');

// $server_name = config('main.server_name', 'main');
$server_name =  '-' . $mode;

return [
    // http服务配置
    'webman' . $server_name   => [
        'handler'     => Http::class,
        'listen'      => 'http://127.0.0.1:' . ($mode == 'h5' ? '9797' : '8787'),
        'count'       => $mode == 'h5' ? cpu_count() * 3 : cpu_count() * 2,
        'user'        => 'www',
        'group'       => 'www',
        'reusePort'   => false,
        // 'eventLoop'   => '',
        'eventLoop'   => \Workerman\Events\Swoole::class,
        'context'     => [],
        'constructor' => [
            'requestClass' => Request::class,
            'logger'       => Log::channel('default'),
            'appPath'      => app_path(),
            'publicPath'   => public_path(),
        ],
    ],
    // 系统定时任务
    'cmyiot.timer' . $server_name   => [
        'handler'     => app\process\SysCron::class,
        'count'       => $mode == 'h5' ? 1 : cpu_count(),
    ],
    // 推送定时任务
    'cmyiot.task' . $server_name   => [
        'handler'     => app\process\SysTask::class,
        'count'       => $mode == 'h5' ? 1 : ceil(cpu_count() / 2),
    ],
    // File update detection and automatic reload
    'monitor' => [
        'handler'     => app\process\Monitor::class,
        'reloadable'  => false,
        'constructor' => [
            // Monitor these directories
            'monitorDir'        => array_merge([
                app_path(),
                config_path(),
                base_path() . '/process',
                base_path() . '/support',
                base_path() . '/resource',
                base_path() . '/.env',
            ], glob(base_path() . '/plugin/*/app'), glob(base_path() . '/plugin/*/config'), glob(base_path() . '/plugin/*/api')),
            // Files with these suffixes will be monitored
            'monitorExtensions' => [
                'php',
                'html',
                'htm',
                'env',
            ],
            'options'           => [
                'enable_file_monitor'   => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/',
                'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
            ],
        ],
    ],
];

报错信息

Error: Call to undefined method Workerman\Protocols\Http\Request::getRealIp() in /www/wwwroot/iot.xxx.cn/vendor/workerman/webman-framework/src/Exception/ExceptionHandler.php:68 Stack trace: #0 /www/wwwroot/iot.xxx.cn/app/common/exception/Http.php(44): Webman\Exception\ExceptionHandler->report() #1 /www/wwwroot/iot.xxx.cn/vendor/workerman/webman-framework/src/App.php(283): app\common\exception\Http->report() #2 /www/wwwroot/iot.xxx.cn/vendor/workerman/webman-framework/src/App.php(357): Webman\App::exceptionResponse() #3 /www/wwwroot/iot.xxx.cn/vendor/workerman/webman-framework/src/App.php(671): Webman\App::Webman\{closure}() #4 /www/wwwroot/iot.xxx.cn/vendor/workerman/webman-framework/src/App.php(159): Webman\App::findRoute() #5 /www/wwwroot/iot.xxx.cn/vendor/workerman/workerman/src/Connection/TcpConnection.php(676): Webman\App->onMessage() #6 /www/wwwroot/iot.xxx.cn/vendor/workerman/workerman/src/Events/Swoole.php(288): Workerman\Connection\TcpConnection->baseRead() #7 [internal function]: Workerman\Events\Swoole->Workerman\Events\{closure}() #8 {main}

截图报错信息里报错文件相关代码

截图

操作系统及workerman/webman等框架组件具体版本

操作系统:CentOS 7.9.2009 x86_64(Py3.7.9)
webman版本:v2.1.2
workerman版本:v5.1.1
swoole版本:v5.1.4
Nginx版本: 1.26.1

截图

110 1 0
1个回答

Tinywan
×
🔝