Channel.php 827 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\common\util;
  3. use Channel\Client;
  4. use Exception;
  5. use think\facade\Log;
  6. class Channel
  7. {
  8. public function __construct(){
  9. }
  10. /**
  11. * 通知websocket进程
  12. * @param string $events 事件
  13. * @param string $type 类型
  14. * @param int $connection_ids 连接id
  15. * @param array $data 传输的数据报文
  16. */
  17. public function sendChannel(string $events, string $type, int $connection_ids=0, array $data = []){
  18. try {
  19. Client::connect(config('channel.ip'),config('channel.port'));
  20. }catch (Exception $e) {
  21. // 异常捕获
  22. Log::write( $e->getMessage(),'notice');
  23. }
  24. Client::publish($events,[
  25. 'type'=>$type,
  26. 'data'=>$data,
  27. 'connection_ids'=>$connection_ids,
  28. ]);
  29. }
  30. }