A PHP WebSocket library. With following features:
- Server
- Client
- WSS Support (WebSocket over SSL)
- Autobahn test suite passed (WebSocket test suite reference)
- Binary/text messages supported
- Built on top of reactphp (async socket communication)
- Not dependent of any other big framework/library which mean you can use it with guzzle (any version) or Symfony (any version)
- Woketo follows semver
- PHP 7+
# The installation is pretty much easier with composer. But you still can use it as git submodule !
composer require "nekland/woketo"
And that's all ! 🙀
The file tests.php
is a basic echo server. That's all you need to make a websocket server with Woketo:
<?php
use Your\Namespace\YourMessageHandler;
use Nekland\Woketo\Server\WebSocketServer;
$server = new WebSocketServer(1337);
$server->setMessageHandler(new YourMessageHandler(), '/path'); // accessible on ws://127.0.0.1:1337/path
$server->start(); // And that's all <3
<?php
// YourMessageHandler.php
namespace Your\Namespace;
use Nekland\Woketo\Core\AbstractConnection;
use Nekland\Woketo\Message\TextMessageHandler;
class YourMessageHandler extends TextMessageHandler
{
public function onConnection(AbstractConnection $connection)
{
// Doing something when the client is connected ?
// This method is totally optional.
}
public function onMessage(string $data, AbstractConnection $connection)
{
// Sending back the received data
$connection->write($data);
}
public function onDisconnect(AbstractConnection $connection)
{
// Doing something when the connection between client/server is disconnecting
// Optionnal
}
}
git clone git@github.com:Nekland/Woketo
cd Woketo
composer install
./bin/phpunit
php tests/echo-server.php
wstest -m fuzzingclient
wstest -m fuzzingserver
php tests/client_autobahn.php
wstest is the Autobahn test tool. You can install it with
sudo pip install autobahntestsuite
.You can read more about the installation of Autobahn on their documentation.
- How to learn more about Woketo usage? RTFM!
- How to get information about how it works internally? Read the docs/dev.md page of doc.
- How to contribute? Read the CONTRIBUTING.md page of doc.
- How to get support? Use Gitter, the issue tracker is not a forum.
You can see what's planned for next versions in the github milestones.
Currently there is no support of the following:
- WebSocket extensions, currently not supported but will probably be in the future
- WAMP implementation will probably never be done by Woketo itself as it's a layer on top of WebSockets. This includes JSON-RPC and other layers up to WebSockets.
Thank you to all code contributors (Hello folliked =)). And to any code reviewer (Hi valanz).
<3