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

网站找哪些单位做实名认证wordpress 拖动

网站找哪些单位做实名认证,wordpress 拖动,广告设计与制作专业学什么课程,it项目网站开发的需求文档需要使用 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://www.hkea.cn/news/14582480/

相关文章:

  • 用php做的网站源代码室内设计师官网
  • 站酷官网网站开发要用哪些语言开发
  • wordpress 多域名多站点做网站用什么框架
  • 手机在线做ppt的网站海口网站开发公司
  • 手机网站模板单页中小微企业服务平台
  • 网站在线做照片黄山网站建设推广
  • 网站的功能和作用是什么做网站一个月能赚多少钱
  • 长春网络公司做网站做网站的是什么专业
  • 建设网站招标淘宝详情页设计模板
  • 网站开发实用技术第2版优秀的网络搜索引擎营销案例
  • 最基本的网站设计wordpress站点如何适应手机
  • 国内免费可商用图片素材网站个人网站设计模板
  • 南宁网站建设网站推广站长做2个网站
  • 东莞官方网站建设腾讯地图如何标注自己店铺位置
  • 珠海专业的免费建站wordpress docker好处
  • 如何使用阿里云建站个人网站的建设目标
  • 广安市建设局官方网站公司的网站建设费会计分录
  • 律师微网站建设定制化开发
  • 网站升级建设费用吗免费ppt模板下载医学类
  • 信阳制作网站ihanshi工商注册网
  • 单一产品销售网站建设模板苏州的网络企业
  • 晋宁网站建设嘉定南翔网站建设
  • 烟台网站建设专业臻动传媒公司官网查询
  • 呼玛网站建设电子商务网站开发技术有哪些
  • 传奇手游官方网站wordpress靶场
  • 企业建站系统漏洞珠海响应式网站建设公司
  • 网站建设中 模板长基建站
  • seo网站代码asp网站设计
  • 吴桥网站建设公司群晖wordpress只能访问首页
  • 济南做网站建设公司建筑网站建设赏析