定制 nailfor/php-websocket-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nailfor/php-websocket-client

Composer 安装命令:

composer require nailfor/php-websocket-client

包简介

a websocket client library for php

README 文档

README

phpWebSocketClient is an WebSocket client library for PHP. Its based on the reactPHP socket-client and added the WebSocket protocol specific functions.

Goal

Goal of this project is easy to use WebSocket client for PHP in a modern architecture without using any php modules.

Example

use nailfor\websocket\ClientFactory;

class WebSocketTest
{
    public function receiveMsg($reason)
    {
        echo "RECEIVE:";
        print_r($reason->getMessage());
    }

    public function afterConnect($reason)
    {
        $data = [
            "somedata" => "peesdata",
        ];
        //'topic' is a TOPIC_NAME from options
        ClientFactory::$client->publish('topic', $data);
    }

    public function errorMsg($reason)
    {
        echo $reason->getMessage(). PHP_EOL;
        exit;
    }
    
    public function closeMsg()
    {
        echo "closed!!!!". PHP_EOL;
        exit;
    }
    
    
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $options = [
            'topics' => [
                //TOPIC_NAME => events[]
                'topic' => [
                    'events' => [
                        //EVENT_NAME=>function 
                        'PUBLISH_RECEIVED'  => [$this, 'receiveMsg'],
                    ],
                ],
            ],
            'connect'   => [$this, 'afterConnect'],
            'timeout'   => [$this, 'errorMsg'],
            'error'     => [$this, 'errorMsg'],
            'close'     => [$this, 'closeMsg'],
        ];

        ClientFactory::run('ws://127.0.0.1:8080', $options);
    }
}

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL
  • 更新时间: 2019-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固