totoro1302/php-websocket-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

totoro1302/php-websocket-client

最新稳定版本:v0.1.7

Composer 安装命令:

composer require totoro1302/php-websocket-client

包简介

Php Websocket Client

README 文档

README

What is it?

Basic implementation of PHP Websocket client that follow RFC6455

Installation

If you wish to install it in your project, require it via composer:

composer require totoro1302/php-websocket-client

Tests

PHPUnit

  • Coverage must be 100% on src/

Stack description

PHP

  • PHP >= 8.2 is required

Extensions

  • extension pcntl

Dependencies

  • psr/log
  • nyholm/psr7
  • psr/http-factory

Run test

Run PHP unit tests

bin/test.sh unit

Run code sniffer

bin/test.sh static

Run PHPStan static

bin/test.sh static-analyze

Run PHP 8.2 compatibility

bin/test.sh php82-compatibility

Run code smell fix

bin/test.sh static-fix

Usage

<?php

use Totoro1302\PhpWebsocketClient\Client;use Totoro1302\PhpWebsocketClient\ClientConfig;

$clientConfig = new ClientConfig(
'myWsClient', // give a name to the connection (mandatory)
'wss://some-ws-srv.com', // websocket server address (mandatory)
10, // connection timeout (optional)
'some_origin.com', // you can specify an origin (optional)
false, // persistent (optional)
['user-agent' => 'myAgent'] // add additional headers (optional)
);

$client = new Client($clientConfig);
$client->connect();
$client->push('Hello world');

while ($client->isRunning()) {
    $data = $client->pull();
    // Do something with the data here
    usleep(mt_rand(50000, 100000)); // You can eventually add some timeout pull delay if needed
}

Auto Respond

The client handles ping/pong logic on both sides. It means it automatically respond to ping frame by a pong frame, and client also send ping frame to the server to check the server is always alive.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-01