我發(fā)現(xiàn)當我頻繁刷新某個接口時,會出現(xiàn)這個問題,請問出現(xiàn)這個問題是什么原因的呢?
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}
/**
* 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.wtbis.cn/
* @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);
}
}
public function onMessage($connection, $request){
var_dump(get_class($request));
parent::onMessage($connection, $request);
}
onMessage加一個打印,請求下看下輸出什么
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、第一行為正常請求時返回的數(shù)據
2、第二條為報錯后返回的數(shù)據
3、接下來3條為報錯后我繼續(xù)刷新的數(shù)據
4、最后一條為我復制一樣的url在新窗口打開的數(shù)據(此時不報錯)
因為我用Visual Studio Code編輯器編輯代碼,使用sftp插件來上傳,但由于服務器上傳有點差,文件上傳要幾秒,我嘗試在保存后,一直刷新,我發(fā)覺在sftp插件上傳成功后立馬刷新,就會出現(xiàn)這個問題,要是等1秒后刷新就不會有那個報錯,還有好奇的是,報錯后繼續(xù)刷新繼續(xù)刷新,就會繼續(xù)報錯(第三點),而復制一樣的url在新窗口打開卻正常(第四點)
平時我用寶塔方式啟動【php /www/wwwroot/項目/start.php start】,為了輸出上述信息,使用的命令為php start.php start
服務器改下文件 vendor/workerman/webman-framework/src/App.php
構造函數(shù)加一行 Http::requestClass(static::$requestClass);
restart 重啟然后試下
添加后人工手動重啟,一樣的手法一樣的錯誤,我發(fā)現(xiàn)只是調試模式下使用外部工具上傳文件才有問題,不過要是每次文件修改完上傳后再人工手動重啟就沒問題