Commit 2cd1f183 authored by 冯超鹏's avatar 冯超鹏

新模块厂链接

parent 3082cb42
Pipeline #62 failed with stages
<?php
namespace App\Console\Commands;
use App\Http\Controllers\Auth\SwooleCommandController;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class chemicalswb extends Command
{
public $ws;
private $token = 'zxc123456789ZXC';
public $time = 10;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'swoolechewb {action?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'swoolechewb';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$action = $this->argument('action');
switch ($action) {
case 'close':
break;
default:
$this->start();
break;
}
}
//开启WebSocket
public function start()
{
$url = config('public.swoolwebsocketurl');
$por = config('public.swoolwebsocketurlpor');
$this->ws = new \swoole_websocket_server('0.0.0.0', 9507); //创建一个端口
$this->ws->set(array(
'reactor_num' => 2, //reactor线程数
'worker_num' => 4, //worker进程数
'backlog' => 128, //Listen队列长度
'max_request' => 10,//最大连接
'daemonize'=>0,//守护进程
));
$this->ws->on('open', function ($ws, $request) {
// //链接成功
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->chemicals(),1);
swoole_timer_tick(6000, function($timerId) use ($ws, $request) {
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->chemicals(),1);
});
});
//监听WebSocket消息事件
$this->ws->on('message', function ($ws, $frame) {
});
$this->ws->on('request', function ($request, $response,$from_id,$fd) {
});
//监听WebSocket连接关闭事件
$this->ws->on('close', function ($ws, $fd) {
echo "client:{$fd} is closed\n";
swoole_timer_clear($this->time);
});
$this->ws->start();
}
}
<?php
namespace App\Console\Commands;
use App\Http\Controllers\Auth\SwooleCommandController;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class firewb extends Command
{
public $ws;
private $token = 'zxc123456789ZXC';
public $time = 10;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'swoolefirewb {action?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'swoolefirewb';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$action = $this->argument('action');
switch ($action) {
case 'close':
break;
default:
$this->start();
break;
}
}
//开启WebSocket
public function start()
{
$url = config('public.swoolwebsocketurl');
$por = config('public.swoolwebsocketurlpor');
$this->ws = new \swoole_websocket_server('0.0.0.0', 9508); //创建一个端口
$this->ws->set(array(
'reactor_num' => 2, //reactor线程数
'worker_num' => 4, //worker进程数
'backlog' => 128, //Listen队列长度
'max_request' => 10,//最大连接
'daemonize'=>0,//守护进程
));
$this->ws->on('open', function ($ws, $request) {
// //链接成功
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->fire(),1);
swoole_timer_tick(6000, function($timerId) use ($ws, $request) {
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->fire(),1);
});
});
//监听WebSocket消息事件
$this->ws->on('message', function ($ws, $frame) {
});
$this->ws->on('request', function ($request, $response,$from_id,$fd) {
});
//监听WebSocket连接关闭事件
$this->ws->on('close', function ($ws, $fd) {
echo "client:{$fd} is closed\n";
swoole_timer_clear($this->time);
});
$this->ws->start();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment