fix: 全模块Critical安全修复 — 防重入+锁+精度+XSS
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Workerman\Worker;
|
||||
|
||||
class WebSocketClient extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'websocket:client {worker_command} {--mode=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'websocket client';
|
||||
|
||||
protected $worker;
|
||||
|
||||
protected $events = [
|
||||
'onWorkerStart',
|
||||
'onConnect',
|
||||
'onMessage',
|
||||
'onClose',
|
||||
'onError',
|
||||
'onBufferFull',
|
||||
'onBufferDrain',
|
||||
'onWorkerStop',
|
||||
'onWorkerReload'
|
||||
];
|
||||
|
||||
protected $callback_class;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$class_name = config('websocket.client.callback_class');
|
||||
$class_name = \App\Utils\Workerman\WorkerCallback::class;
|
||||
$process_num = config('websocket.client.process_num');
|
||||
// $process_num = 8;
|
||||
// $process_num = 1;
|
||||
$this->callback_class = new $class_name();
|
||||
$this->worker = new Worker();
|
||||
$this->worker->count = $process_num;
|
||||
$this->worker->name = 'Huobi Websocket';
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->initWorker();
|
||||
$this->bindEvent();
|
||||
$this->worker->runAll();
|
||||
}
|
||||
|
||||
protected function initWorker()
|
||||
{
|
||||
global $argv;
|
||||
$argv[1] = $command = $this->argument('worker_command');
|
||||
$mode = $this->option('mode');
|
||||
isset($mode) && $argv[2] = '-' . $mode;
|
||||
}
|
||||
|
||||
protected function bindEvent()
|
||||
{
|
||||
foreach ($this->events as $key => $event) {
|
||||
method_exists($this->callback_class, $event) && $this->worker->$event = [$this->callback_class, $event];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user