phpsoftbox / broadcaster
Broadcaster component for the PhpSoftBox framework (Pushr)
Requires
- php: ^8.5
- phpsoftbox/config: dev-master
- psr/http-message: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.93
- phpsoftbox/cli-app: dev-master
- phpsoftbox/cs-fixer: ^1.1.0
- phpunit/phpunit: ^11.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-02 14:14:09 UTC
README
About
phpsoftbox/broadcaster — компонент для запуска WebSocket сервера и обмена сообщениями между сервисами. Драйвер Pushr реализует собственный протокол с авторизацией по app_id и signature.
Ключевые свойства:
- сервер
PushrServer(WebSocket) - клиент
PushrClientдля публикации/подписки - подписи
PushrSignature - подписи каналов
PushrChannelAuth - реестр каналов
ChannelRegistry - поддержка каналов (rooms), включая приватные
Quick Start
Запуск сервера:
use PhpSoftBox\Broadcaster\Pushr\PushrAppRegistry; use PhpSoftBox\Broadcaster\Pushr\PushrServer; $registry = new PushrAppRegistry([ 'app-1' => 'secret-1', ]); $server = new PushrServer($registry, host: '0.0.0.0', port: 8080); $server->run();
Подключение клиентом:
use PhpSoftBox\Broadcaster\Pushr\PushrClient; $client = new PushrClient('127.0.0.1', 8080, 'app-1', 'secret-1'); $client->connect(); $client->subscribe('news'); $client->publish('news', 'message', ['text' => 'hello']);
Публикация из PHP-кода без постоянного подключения:
use PhpSoftBox\Broadcaster\Pushr\PushrPublisher; use PhpSoftBox\Broadcaster\Pushr\PushrPublisherOptions; $publisher = new PushrPublisher( 'app-1', 'secret-1', '127.0.0.1', 8080, options: new PushrPublisherOptions( connectTimeoutSeconds: 0.5, handshakeTimeoutSeconds: 0.5, readTimeoutSeconds: 0.5, writeTimeoutSeconds: 0.5, ), ); $publisher->publish('news', 'message', ['text' => 'hello']); $publisher->publishMany(['news', 'private.user.10'], 'message', ['text' => 'hello']);
publishMany() открывает одно соединение для всех каналов. Синхронный publisher
не скрывает ошибки: приложение само решает, должна ли ошибка публикации прервать
операцию. Для гарантированной доставки через очередь или transactional outbox
используйте DeferredPushrPublisher со своей реализацией
PushrPublicationDispatcherInterface.