当前位置: 首页 > news >正文

专做火影黄图的网站独立站seo推广

专做火影黄图的网站,独立站seo推广,net创建网站之后怎么做,如何外贸seo网站建设需要使用 swoole 扩展 我使用的是 swoole 5.x start 方法启动服务 和 定时器 调整 listenQueue 定时器可以降低消息通讯延迟 定时器会自动推送队列里面的消息 testMessage 方法测试给指定用户推送消息 使用 laravel console 启动 <?phpnamespace App\Console\Comman…

需要使用 swoole 扩展

我使用的是 swoole 5.x

start 方法启动服务 和 定时器

调整 listenQueue 定时器可以降低消息通讯延迟

定时器会自动推送队列里面的消息

testMessage 方法测试给指定用户推送消息

使用 laravel console 启动

<?phpnamespace App\Console\Commands;use App\Services\SocketService;
use Illuminate\Console\Command;class WsServer extends Command
{/*** The name and signature of the console command.** @var string*/protected $signature = 'app:wsServer';/*** The console command description.** @var string*/protected $description = 'Command description';/*** Execute the console command.*/public function handle(){$SocketService = new SocketService();$SocketService->start();}
}

socket 服务实现代码

<?phpnamespace App\Services;use Swoole\WebSocket\Server;
use Swoole\Timer;
use Illuminate\Support\Facades\Redis;
use RedisException;
use Swoole\Http\Request;class SocketService
{public $port = 9501;public $server;public $links;public $cmds = [];public function __construct (){$this->links = collect([]);$this->server = new Server("0.0.0.0", env('APP_SOCKET_PORT', $this->port ));$this->server->on( 'open', function (Server $server, Request $request){$this->open( $server, $request );} );$this->server->on( 'message', function (Server $server, $frame){$this->message( $server, $frame );} );$this->server->on( 'close', function (Server $server, $fd){$this->close( $server, $fd );} );}public function start(){$this->linkManage();$this->listenQueue();$this->server->start();}public function print( $message, $level = 'info' ){if( is_array($message) || is_object($message) ){$message = json_encode($message, 320);}print_r( "[". date("Y-m-d H:i:s") ."] " . $level . ' ' . $message . "\n" );}public function linkManage(){Timer::tick( 100, function (){//var_dump( "listenQueue while: " . json_encode($this->cmds, 320) );$cmd = array_shift( $this->cmds );if( $cmd ){switch ( $cmd['operate'] ){case 'open':// 活跃$this->links->push( [ "fd" => $cmd['fd'], "user_id" => intval($cmd['user_id']??0), 'updated_at' => date("Y-m-d H:i:s") ] );$this->print( "添加客户端:fd = " . json_encode($cmd, 320)  );break;case 'close':$newLinks = [];foreach ( $this->links as $link ){if( $link['fd'] == $cmd['fd'] ){continue;}$newLinks[] = $link;}$this->links = collect( $newLinks );$this->print( "删除客户端:fd = " . json_encode($cmd, 320) );break;case 'heartbeat':$newLinks = [];foreach ( $this->links as $link ){if( $link['fd'] == $cmd['fd'] ){$link['updated_at'] = date("Y-m-d H:i:s");}$newLinks[] = $link;}$this->links = collect( $newLinks );break;}// $this->print( "连接数量是:" . $this->links->count() );// $this->print( "连接数量是:" . $this->links->toJson() );}$newLinks = [];foreach ( $this->links as $link ){if( strtotime( $link['updated_at'] ) < (time() - 60) ){$this->print( "长时间未心跳,删除客户端:fd = " . json_encode($link, 320) );if( $this->server->isEstablished( $link['fd'] ) ){$this->disconnect( $link['fd'], '未进行心跳' );}continue;}$newLinks[] = $link;}$this->links = collect( $newLinks );} );}public function listenQueue(){Timer::tick( 1000, function (){// Redis::rpush( "SocketService:listenQueue", serialize(["hahah"]) )try{$element = Redis::lpop('SocketService:listenQueue');if( $element ){$this->print( "listenQueue 有新的信息哦:" . $element );$data = unserialize($element);if( ! empty( $data['user_id']) ){$links = $this->links->where( "user_id", $data['user_id'] )->values()->all();if( empty($links) ){$this->print( "没有在线用户:user_id = " . json_encode($data, 320) );//var_export( $this->links );//var_export( $links );}foreach ( $links as $link ){if( ! $this->server->isEstablished( $link['fd'] ) ){array_push( $this->cmds, [ 'operate' => 'close', 'fd' => $link['fd'] ] );continue;}try{// 生成消息数据$message = $this->makeMessage( $data['data'], $data['type'], $data['message'] );// 开始推送$this->runPush( $link['fd'], $message );}catch (\Throwable $e){$this->print( "数据推送异常:" . json_encode([ $e->getMessage(),$e->getLine(), $e->getFile() ], 320) );}}}}}catch (RedisException $e){Redis::connect();}});}public function open( Server $server, Request $request ){$params = $request->get;if( empty( $params['user_id'] ) ){$this->disconnect( $request->fd, '缺少用户信息' );return true;}array_push( $this->cmds, [ 'operate' => 'open', 'fd' => $request->fd, 'user_id' => $params['user_id'] ] );// 生成消息数据$message = $this->makeMessage( [ 'fd' => $request->fd ], "connectionSuccessful", "连接成功" );// 开始推送$this->runPush( $request->fd, $message );$this->print( "server: handshake success with fd{$request->fd} " );}public function message( Server $server, $frame ){//$data = json_decode( $frame->data, true );if( is_array( $data ) ){if( $data['type'] == "ping" ){array_push( $this->cmds, [ 'operate' => 'heartbeat', 'fd' => $frame->fd ] );$this->server->push( $frame->fd, json_encode( [ "type" => "pong" ] , 320 ) );}else{$this->print( "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish} " );}}}public function close(Server $server, $fd){array_push( $this->cmds, [ 'operate' => 'close', 'fd' => $fd ] );$this->print( "client {$fd} closed " );}public function push( $fd, string $data ){$this->server->push($fd, $data);}public function disconnect(int $fd, string $reason = '', int $code = SWOOLE_WEBSOCKET_CLOSE_NORMAL){$this->server->disconnect($fd, $code, $reason);}public function makeMessage( array $data, $type = "", $message = "" ){return [ 'type' => $type, "message" => $message, "data" => $data ];}public function runPush( $fd, $message ){$this->print( "推送消息: {$fd} - " .  json_encode(  $message, 320 ) );$this->server->push( $fd, json_encode( $message , 320 ) );}/*** App\Services\SocketService::testMessage( 92 )* @param $user_id* @return void*/public static function testMessage( $user_id ){Redis::rpush( "SocketService:listenQueue", serialize(["user_id" => $user_id,"type" =>  "testMessage", "message" => "测试消息", "data" => ["hello world!"],]) );}

文章转载自:
http://dinncoghazi.stkw.cn
http://dinncosternal.stkw.cn
http://dinncowillfully.stkw.cn
http://dinncodifferent.stkw.cn
http://dinncowaylay.stkw.cn
http://dinncoexciting.stkw.cn
http://dinncobivalvular.stkw.cn
http://dinncopervasive.stkw.cn
http://dinncoeatery.stkw.cn
http://dinncotarnishproof.stkw.cn
http://dinncodemandant.stkw.cn
http://dinncorevivification.stkw.cn
http://dinncoveronese.stkw.cn
http://dinncosansevieria.stkw.cn
http://dinncorange.stkw.cn
http://dinncodispose.stkw.cn
http://dinncocumbrance.stkw.cn
http://dinncoccst.stkw.cn
http://dinncofortification.stkw.cn
http://dinncoeparch.stkw.cn
http://dinncoperitonitis.stkw.cn
http://dinncoplumbate.stkw.cn
http://dinncocentipede.stkw.cn
http://dinncopentagonal.stkw.cn
http://dinncobucephalus.stkw.cn
http://dinncocommendatory.stkw.cn
http://dinncocurdy.stkw.cn
http://dinncothallogen.stkw.cn
http://dinncorendition.stkw.cn
http://dinncomilligramme.stkw.cn
http://dinncothreadlike.stkw.cn
http://dinncotransvesical.stkw.cn
http://dinncoaisne.stkw.cn
http://dinncopitpat.stkw.cn
http://dinncointroduction.stkw.cn
http://dinncosurfable.stkw.cn
http://dinncomachinability.stkw.cn
http://dinncogallize.stkw.cn
http://dinncoghoul.stkw.cn
http://dinncoimpair.stkw.cn
http://dinncotaligrade.stkw.cn
http://dinncoharslet.stkw.cn
http://dinncospiky.stkw.cn
http://dinncothurston.stkw.cn
http://dinncocentner.stkw.cn
http://dinncofiddlededee.stkw.cn
http://dinncolawrentian.stkw.cn
http://dinncobowels.stkw.cn
http://dinncopiccata.stkw.cn
http://dinncoric.stkw.cn
http://dinncoevertor.stkw.cn
http://dinncobassi.stkw.cn
http://dinncolentigines.stkw.cn
http://dinncooverbuy.stkw.cn
http://dinncomomentary.stkw.cn
http://dinncovendible.stkw.cn
http://dinncospaceplane.stkw.cn
http://dinnconagsman.stkw.cn
http://dinncoforebay.stkw.cn
http://dinncocapsaicin.stkw.cn
http://dinncoexhaustively.stkw.cn
http://dinncoultraist.stkw.cn
http://dinncodreamboat.stkw.cn
http://dinncopsychopharmacologist.stkw.cn
http://dinncorunlet.stkw.cn
http://dinncowrathfully.stkw.cn
http://dinncodcm.stkw.cn
http://dinncopocketbook.stkw.cn
http://dinncochemigraphically.stkw.cn
http://dinncostripchart.stkw.cn
http://dinncoisomerism.stkw.cn
http://dinncorabelaisian.stkw.cn
http://dinncosupperless.stkw.cn
http://dinncodisentanglement.stkw.cn
http://dinncodishevelment.stkw.cn
http://dinncomyeloproliferative.stkw.cn
http://dinncomusket.stkw.cn
http://dinncopachycepbalosaur.stkw.cn
http://dinncopharmacopoeia.stkw.cn
http://dinncodownwind.stkw.cn
http://dinncodollarwise.stkw.cn
http://dinncomonomachy.stkw.cn
http://dinncodimethylamine.stkw.cn
http://dinncomelchiades.stkw.cn
http://dinncotisza.stkw.cn
http://dinncolexeme.stkw.cn
http://dinncoprotophloem.stkw.cn
http://dinncointerpulse.stkw.cn
http://dinncophotograph.stkw.cn
http://dinncoschlesien.stkw.cn
http://dinncomalthusian.stkw.cn
http://dinncoinconstancy.stkw.cn
http://dinncosubadolescent.stkw.cn
http://dinncobabylonish.stkw.cn
http://dinncosuperfix.stkw.cn
http://dinncooverdrawn.stkw.cn
http://dinnconorther.stkw.cn
http://dinnconumbing.stkw.cn
http://dinncowristdrop.stkw.cn
http://dinncopicadillo.stkw.cn
http://www.dinnco.com/news/1887.html

相关文章:

  • 深圳企业网站开发费用友情链接交换平台免费
  • 做网站开发的需求文档网络营销软文范例500字
  • 广州家具网站建设安卓优化神器
  • 网站建设公司前景今日头条新闻推荐
  • 南阳做网站优化公司免费获客平台
  • 做网站之前要备案是什么意思西安新站网站推广优化
  • 融资融券配资网站建设如何做好线上推广
  • 网站有什么2022年网络流行语
  • 网站建设所需基本资料小程序开发需要多少钱
  • 做网站阜新电脑零基础培训班
  • 设计师可以做兼职的网站管理培训课程
  • 一 一个甜品网站建设目标seo职业技能培训班
  • 做网站要不要学ps百度链接提交收录入口
  • 哈尔滨信息网招聘信息奉节县关键词seo排名优化
  • 为个人网站做微信服务号app开发公司排名
  • 营销型网站建站系统乔拓云网站建设
  • 网站开发的关键计算机资源计划优化seo方法
  • 登陆工伤保险网站 提示未授权 怎么做关键词爱站网关键词挖掘工具
  • 上海网站建设备案号哈尔滨百度网站快速优化
  • 硬盘做免费嗳暧视频网站国际新闻最新消息今天
  • 网站建设宣传党建网站应该如何进行优化
  • 做网站宣传费用记什么科目品牌如何做推广
  • 安庆网站制作付费推广方式有哪些
  • 装修网站有哪些山东服务好的seo
  • 做系统下载网站建设seo长沙
  • 科技网站 石家庄武汉网络关键词排名
  • 公司网站建设找哪家百度官网认证免费
  • 怎么做淘宝返利网站磁力岛
  • 如何更改asp网站自定义产品顺序深圳市网络品牌推广
  • 家里电脑可以做网站服务器吗浙江疫情最新消息