highperapp/websockets 问题修复 & 功能扩展

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

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

highperapp/websockets

最新稳定版本:10

Composer 安装命令:

composer require highperapp/websockets

包简介

High-performance WebSocket server with O(1) indexed broadcasting. Fully compatible with PHP 8.3 & 8.4 for modern async applications.

README 文档

README

PHP Version Performance WebSocket Tests

High-performance WebSocket server with O(1) indexed broadcasting and zero-downtime connection preservation. Works standalone or with HighPer Framework.

🔄 Standalone Library: Works independently in any PHP application - no framework required!

Info: Full Amp v3 compatibility with improved type safety and API updates

🚀 Features

Indexed Broadcasting

  • O(1) Broadcasting: IndexedBroadcaster for constant-time message delivery
  • Channel Indexing: Efficient subscriber management per channel
  • Zero-Downtime Preservation: Maintain connections during deployments
  • Connection Migration: Seamless connection handoff between workers

🎯 Performance Optimizations

  • High Performance: Built on AMPHP v3 for true async/await
  • Real-time Streaming: Advanced streaming with backpressure handling
  • Production-Ready: Enterprise WebSocket server implementation
  • Ultra-Low Latency: Sub-millisecond message broadcasting
  • Framework Integration: Deep HighPer Framework integration
  • Memory Efficient: Optimized connection and channel management

Installation

composer require highperapp/websockets

Quick Start

<?php
require 'vendor/autoload.php';

use HighPerApp\HighPer\WebSockets\StreamingWebSocketHandler;
use HighPerApp\HighPer\WebSockets\WebSocketServerHandler;
use Psr\Log\NullLogger;

// Create WebSocket handler with logger
$logger = new NullLogger();
$handler = new StreamingWebSocketHandler($logger, [
    'enable_streaming' => true,
    'backpressure_limit' => 1000
]);

// Create and start WebSocket server
// Recommended: HighPer Container for optimal performance
$container = new \HighPerApp\HighPer\Container\Container();
// Alternative: Any PSR-11 compatible container
// $container = new \DI\Container();

$server = new WebSocketServerHandler($container, '0.0.0.0', 8080);
$server->start();

🎪 Recommended Ecosystem

For optimal performance and seamless integration, use with the HighPer ecosystem:

# Install the complete high-performance stack
composer require highperapp/websockets
composer require highperapp/container

Why HighPer Container?

  • <0.001ms service resolution - Perfect for high-frequency WebSocket operations
  • 🚀 40-60% faster than generic PSR-11 containers
  • 🔧 Build-time compilation - Zero runtime overhead
  • 🎯 C10M ready - Handles extreme concurrency scenarios
  • 🔄 Object pooling - Efficient resource management for persistent connections

Requirements

  • PHP 8.3+ or PHP 8.4+ - Full support for both versions
  • AMPHP v3+ - Async/await WebSocket server implementation
  • ext-json - JSON message encoding/decoding
  • PSR Container - For dependency injection (HighPer Container recommended for optimal performance)
  • PSR Logger - For logging (any PSR-3 compatible logger)
  • Modern PHP Features - Leverages PHP 8.3/8.4 performance improvements

PHP Version Compatibility

This library is fully tested and optimized for:

PHP 8.3 (LTS)

  • Full feature support
  • Production-ready performance
  • All modern PHP 8.3 features utilized

PHP 8.4 (Latest)

  • Complete compatibility
  • Enhanced performance benefits
  • Future-ready implementation

🔧 Modern PHP Features Used

  • Strict Types: declare(strict_types=1) throughout
  • Constructor Property Promotion: Clean, concise code
  • Union Types: Flexible parameter handling
  • Attributes: Modern PHPUnit test annotations
  • Performance Optimizations: JIT compiler ready

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-06