我發(fā)現(xiàn)當(dāng)我頻繁刷新某個(gè)接口時(shí),會(huì)出現(xiàn)這個(gè)問(wèn)題,請(qǐng)問(wèn)出現(xiàn)這個(gè)問(wèn)題是什么原因的呢?
Error: Call to undefined method Workerman\Protocols\Http\Request::getRealIp() in /www/wwwroot/[項(xiàng)目]/vendor/workerman/webman-framework/src/Exception/ExceptionHandler.php:68
Stack trace:
#0 /www/wwwroot/[項(xiàng)目]/vendor/workerman/webman-framework/src/support/exception/Handler.php(35): Webman\Exception\ExceptionHandler->report()
#1 /www/wwwroot/[項(xiàng)目]/vendor/workerman/webman-framework/src/App.php(280): support\exception\Handler->report()
#2 /www/wwwroot/[項(xiàng)目]/vendor/workerman/webman-framework/src/App.php(354): Webman\App::exceptionResponse()
#3 /www/wwwroot/[項(xiàng)目]/vendor/workerman/webman-framework/src/App.php(150): Webman\App::Webman\{closure}()
#4 /www/wwwroot/[項(xiàng)目]/app/process/Bot.php(49): Webman\App->onMessage()
#5 /www/wwwroot/[項(xiàng)目]/vendor/workerman/workerman/src/Connection/TcpConnection.php(676): app\process\Bot->onMessage()
#6 /www/wwwroot/[項(xiàng)目]/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加一個(gè)打印,請(qǐng)求下看下輸出什么
string(15) "support\Request"
/www/wwwroot/[項(xiàng)目]/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、第一行為正常請(qǐng)求時(shí)返回的數(shù)據(jù)
2、第二條為報(bào)錯(cuò)后返回的數(shù)據(jù)
3、接下來(lái)3條為報(bào)錯(cuò)后我繼續(xù)刷新的數(shù)據(jù)
4、最后一條為我復(fù)制一樣的url在新窗口打開(kāi)的數(shù)據(jù)(此時(shí)不報(bào)錯(cuò))
因?yàn)槲矣肰isual Studio Code編輯器編輯代碼,使用sftp插件來(lái)上傳,但由于服務(wù)器上傳有點(diǎn)差,文件上傳要幾秒,我嘗試在保存后,一直刷新,我發(fā)覺(jué)在sftp插件上傳成功后立馬刷新,就會(huì)出現(xiàn)這個(gè)問(wèn)題,要是等1秒后刷新就不會(huì)有那個(gè)報(bào)錯(cuò),還有好奇的是,報(bào)錯(cuò)后繼續(xù)刷新繼續(xù)刷新,就會(huì)繼續(xù)報(bào)錯(cuò)(第三點(diǎn)),而復(fù)制一樣的url在新窗口打開(kāi)卻正常(第四點(diǎn))
平時(shí)我用寶塔方式啟動(dòng)【php /www/wwwroot/項(xiàng)目/start.php start】,為了輸出上述信息,使用的命令為php start.php start
服務(wù)器改下文件 vendor/workerman/webman-framework/src/App.php
構(gòu)造函數(shù)加一行 Http::requestClass(static::$requestClass);
restart 重啟然后試下
添加后人工手動(dòng)重啟,一樣的手法一樣的錯(cuò)誤,我發(fā)現(xiàn)只是調(diào)試模式下使用外部工具上傳文件才有問(wèn)題,不過(guò)要是每次文件修改完上傳后再人工手動(dòng)重啟就沒(méi)問(wèn)題