WebSocket Client for PHP >= 7.0
You can use WebSocketClient or WebSocketCliClient by environment or your favorite.
For web and CLI environment.
Example:
$client = new WebSocketClient('127.0.0.1', 9502);
$client->connect();
$client->recv(); // hello
$client->push('Some Data');
$body = $client->recv();
var_dump($body);
$client->close();For CLI environment only but can use async mode with more performance..
This class need to install openswoole php extension.
Example:
use Swoole\Coroutine as Co;
Co\run(function() {
$client = new WebSocketCliClient('127.0.0.1', 9502);
$client->connect();
$client->recv(); // hello
$client->push('Some Data');
$body = $client->recv();
var_dump($body);
$client->close();
});MIT