请求时发现报错:getRealIp

dgkerry

问题描述

我发现当我频繁刷新某个接口时,会出现这个问题,请问出现这个问题是什么原因的呢?

报错信息

Error: Call to undefined method Workerman\Protocols\Http\Request::getRealIp() in /www/wwwroot/[项目]/vendor/workerman/webman-framework/src/Exception/ExceptionHandler.php:68
Stack trace:
#0 /www/wwwroot/[项目]/vendor/workerman/webman-framework/src/support/exception/Handler.php(35): Webman\Exception\ExceptionHandler->report()
#1 /www/wwwroot/[项目]/vendor/workerman/webman-framework/src/App.php(280): support\exception\Handler->report()
#2 /www/wwwroot/[项目]/vendor/workerman/webman-framework/src/App.php(354): Webman\App::exceptionResponse()
#3 /www/wwwroot/[项目]/vendor/workerman/webman-framework/src/App.php(150): Webman\App::Webman\{closure}()
#4 /www/wwwroot/[项目]/app/process/Bot.php(49): Webman\App->onMessage()
#5 /www/wwwroot/[项目]/vendor/workerman/workerman/src/Connection/TcpConnection.php(676): app\process\Bot->onMessage()
#6 /www/wwwroot/[项目]/vendor/workerman/workerman/src/Events/Swoole.php(288): Workerman\Connection\TcpConnection->baseRead()
#7 [internal function]: Workerman\Events\Swoole->Workerman\Events\{closure}()
#8 {main}

config/process

/**
 * This file is part of webman.
 *
 * 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 support\Log;
use support\Request;
use app\process\Http;
use app\process\Bot;
use app\process\Task;
global $argv;

return [
    'webman' => [
        'handler' => Bot::class,
        'listen' => 'http://0.0.0.0:8787',
        'count' => 1,
        'user' => '',
        'group' => '',
        'reusePort' => false,
        'eventLoop' => Workerman\Events\Swoole::class,
        'context' => [],
        'constructor' => [
            'requestClass' => Request::class,
            'logger' => Log::channel('default'),
            'appPath' => app_path(),
            'publicPath' => public_path()
        ]
    ],
    'task'=>[
        'handler'  => Task::class,
        'eventLoop' => Workerman\Events\Swoole::class,
    ],
    // 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 === '/',
            ]
        ]
    ]
];
###app\process\Bot;
<?php

namespace app\process;

use Webman\App;
use app\service\SyncBinance;
use Workerman\Timer;
use Workerman\Coroutine\Context;
use diyvendor\logger\Log;
use React\Async;
class Bot extends App
{
    public function onWorkerStart($worker)
    {

        parent::onWorkerStart($worker);
    }
    public function onMessage($connection, $request){
        parent::onMessage($connection, $request);
    }

}
212 2 1
2个回答

walkor 打赏

可能你配置有问题,发下 config/process.php

  • dgkerry 13天前

    已在帖子上补上这个文件代码,出现这个问题,不知道是不是我修改了文件后网站重新运行或者说用了梯子(有时候要去google搜索问题时用)

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

onMessage加一个打印,请求下看下输出什么

  • dgkerry 13天前

    string(15) "support\Request"
    /www/wwwroot/[项目]/app/controller/IndexController.php updated and reload
    Workerman[start.php] reloading
    string(32) "Workerman\Protocols\Http\Request"
    string(32) "Workerman\Protocols\Http\Request"
    string(32) "Workerman\Protocols\Http\Request"
    string(15) "support\Request"

    1、第一行为正常请求时返回的数据
    2、第二条为报错后返回的数据
    3、接下来3条为报错后我继续刷新的数据
    4、最后一条为我复制一样的url在新窗口打开的数据(此时不报错)

    因为我用Visual Studio Code编辑器编辑代码,使用sftp插件来上传,但由于服务器上传有点差,文件上传要几秒,我尝试在保存后,一直刷新,我发觉在sftp插件上传成功后立马刷新,就会出现这个问题,要是等1秒后刷新就不会有那个报错,还有好奇的是,报错后继续刷新继续刷新,就会继续报错(第三点),而复制一样的url在新窗口打开却正常(第四点)

  • walkor 13天前

    启动命令是什么

  • dgkerry 13天前

    平时我用宝塔方式启动【php /www/wwwroot/项目/start.php start】,为了输出上述信息,使用的命令为php start.php start

  • dgkerry 13天前

    我直接在服务器上修改,没有发现上述问题,就是使用本地编辑器修改并使用sftp上传才会出现

  • walkor 13天前

    服务器改下文件 vendor/workerman/webman-framework/src/App.php
    截图
    构造函数加一行 Http::requestClass(static::$requestClass);
    restart 重启然后试下

  • dgkerry 13天前

    添加后人工手动重启,一样的手法一样的错误,我发现只是调试模式下使用外部工具上传文件才有问题,不过要是每次文件修改完上传后再人工手动重启就没问题

  • walkor 13天前

    vendor/workerman/workerman/src/Worker.php
    截图
    加一句 $worker->pauseAccept();

  • walkor 13天前

    然后restart重启

×
🔝