6phere/php-websocket
Composer 安装命令:
composer require 6phere/php-websocket
包简介
Asynchronous WebSocket client
README 文档
README
Asynchronous WebSocket client client library for PHP. Supports HyBi, as well as Hixie #76 (no point).
This was built purely to be a client, as the majority of the WS clients available also contain servers and are very bloated.
Installation
Using composer:
composer require sixphere\php-websocket
Usage
Since this really lends itself to being an asynchronous app, it is built to use the React event loops and resolver since there's a good chance they'll be in your project already and this lets you attach to the same loop.
$loop = \React\EventLoop\Factory::create(); $dns_factory = new React\Dns\Resolver\Factory(); $resolver = $dns_factory->createCached('8.8.8.8', $loop); $client = new \Sixphere\WebSocket\Client('ws://127.0.0.1:1337/chat', $loop, $resolver); //Most WS servers will complain/forbid if there is no origin header $client->setOrigin('127.0.0.1'); $client->connect(); $client->on('stateChange', function($newState){ echo "State changed to: $newState\n"; }); $client->on('message', function($message) use ($client){ echo "New message: \n"; echo $message; $client->send('This is a response message'); }); $loop->run();
Other available events are connecting, connect, disconnecting, disconnect
HTTP basic auth is also supported via the URI inf the form user:pass@host
Any feedback is most welcome
This is a fork from: https://github.com/calcinai/bolt
统计信息
- 总下载量: 115
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-18