프로젝트
GitHub에서 보기
sirn-se/websocket-php
소개
[php-lib] WebSocket client and server in PHP
웹 및 앱 개발What you can do
- Client and multi-connection Server
- ws (TCP) and wss (SSL) support
- Listener callbacks on incoming messages and other events
- Close and Ping/Pong handling (standard middlewares)
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
Websocket Client and Server for PHP
This library contains WebSocket client and server for PHP.
The client and server provides methods for reading and writing to WebSocket streams.
This repo replaces the abandoned textalk/websocket repo
and is maintained by Sören Jensen, who has been maintaining the original since v1.3.
Some features
- Client and multi-connection Server
ws(TCP) andwss(SSL) support- Listener callbacks on incoming messages and other events
- Close and Ping/Pong handling (standard middlewares)
- Deflate compression (optional middleware)
- Additional optional middlewares and ability to create own middlewares
- Support message fragmentation and payload masking
- Support custom opcode messages
Documentation
- Documentation
- Client - The WebSocket client
- Server - The WebSocket server
- Changelog - The changelog of this repo
- Contributing - Contributors and requirements
- Examples - Examples
Migration
- v1 -> v2 - How to migrate from v1 to v2
- v2 -> v3 - How to migrate from v2 to v3
- v3 -> v4 - How to migrate from v3 to v4
Installing
Preferred way to install is with Composer.
composer require phrity/websocket
Client
The client can read and write on a WebSocket stream.
Set up a WebSocket Client for continuous subscription
$client = new WebSocket\Client("wss://echo.websocket.org/");
$client
// Add standard middlewares
->addMiddleware(new WebSocket\Middleware\CloseHandler())
->addMiddleware(new WebSocket\Middleware\PingResponder())
// Listen to incoming Text messages
->onText(function (WebSocket\Client $client, WebSocket\Connection $connection, WebSocket\Message\Message $message) {
// Act on incoming message
echo "Got message: {$message->getContent()} \n";
// Possibly respond to server
$client->text("I got your your message");
})
->start();
Set up a WebSocket Client for request/response strategy.
$client = new WebSocket\Client("wss://echo.websocket.org/");
$client
// Add standard middlewares
->addMiddleware(new WebSocket\Middleware\CloseHandler())
->addMiddleware(new WebSocket\Middleware\PingResponder())
;
// Send a message
$client->text("Hello WebSocket.org!");
// Read response (this is blocking)
$message = $client->receive();
echo "Got message: {$message->getContent()} \n";
// Close connection
$client->close();
Server
The server is a multi connection, listening server.
Set up a WebSocket Server for continuous listening
$server = new WebSocket\Server();
$server
// Add standard middlewares
->addMiddleware(new WebSocket\Middleware\CloseHandler())
->addMiddleware(new WebSocket\Middleware\PingResponder())
// Listen to incoming Text messages
->onText(function (WebSocket\Server $server, WebSocket\Connection $connection, WebSocket\Message\Message $message) {
// Act on incoming message
echo "Got message: {$message->getContent()} \n";
// Possibly respond to client
$connection->text("I got your your message");
})
->start();
License
관련 프로젝트 살펴보기
불러오는 중…