relaystacks/conduit-php 问题修复 & 功能扩展

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

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

relaystacks/conduit-php

Composer 安装命令:

composer require relaystacks/conduit-php

包简介

Framework-agnostic Unix socket broadcaster for PHP. The transport core of the Conduit ecosystem.

README 文档

README

Framework-agnostic PHP transport for the RelayStacks Conduit broadcasting ecosystem.

Serializes broadcast messages as newline-delimited JSON, optionally signs them with HMAC-SHA256, and writes them to a Unix domain socket. The receiving end is the @relaystacks/conduit-echo Node.js relay server.

Zero framework dependencies — requires only PHP 8.1+.

Installation

composer require relaystacks/conduit-php

Quick Start

use RelayStacks\Conduit\UnixSocketTransport;

$transport = new UnixSocketTransport(
    socketPath: '/home/user/laravel.sock',
    secret: 'your-shared-secret', // optional
);

$success = $transport->send('chat-room', 'NewMessage', [
    'user' => 'Alice',
    'text' => 'Hello!',
]);

API Reference

TransportInterface

The contract for all Conduit transports.

public function send(string $channel, string $event, array $data = []): bool;
Param Type Description
$channel string Channel name (e.g. presence-chat.1)
$event string Broadcast event name
$data array<string, mixed> Arbitrary event payload
Returns bool true if the message was delivered

UnixSocketTransport

The default (and only) transport implementation. Sends JSON frames over a Unix domain socket.

Constructor

Param Type Default Description
$socketPath string (required) Absolute path to the Unix socket file
$timeout int 2 Connect and write timeout in seconds
$secret ?string null Shared HMAC-SHA256 secret. null = unsigned messages

Methods

  • send(string $channel, string $event, array $data = []): bool — Serialize and write the message. Returns true if the full frame was written.

ConduitException

Domain exception extending RuntimeException. Available for consumers to catch Conduit-specific errors.

HMAC Signing

When a $secret is provided, each message is signed with HMAC-SHA256:

  1. The body {channel, event, data} is JSON-encoded
  2. The HMAC is computed over that JSON string: hash_hmac('sha256', $json, $secret)
  3. The hmac field is appended to the body
  4. The complete body (with HMAC) is JSON-encoded again as the final frame

The verifier (conduit-echo) must strip the hmac field and re-encode the remaining body to reproduce the signature. This works because both PHP's json_encode and JavaScript's JSON.stringify produce deterministic key ordering for simple objects.

Wire Format

Each frame is a single line of JSON terminated by \n.

Unsigned:

{"channel":"chat-room","event":"NewMessage","data":{"user":"Alice","text":"Hello!"}}

Signed:

{"channel":"chat-room","event":"NewMessage","data":{"user":"Alice","text":"Hello!"},"hmac":"a1b2c3..."}

Use Without Laravel

This package works with any PHP framework or plain PHP scripts. For Laravel integration (broadcast driver, channel authorization, service provider), see relaystacks/laravel-conduit.

Requirements

  • PHP >= 8.1
  • Unix-like OS (Unix domain sockets are not available on Windows)

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固