Skip to content

Latest commit

 

History

History
145 lines (102 loc) · 4.09 KB

README.md

File metadata and controls

145 lines (102 loc) · 4.09 KB

Woketo

⚠️ Due to the lack of usage (barely nobody use it), this I will not make the effort to make it compatible with PHP 8. Therefore this library is deprecated and you should not use it. ⚠️

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

Build Status Scrutinizer Code Quality Code Coverage

Requirements

  • PHP 7+

How to install

# 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 ! 🙀

How to use it

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
    }
}

How to test

Unit tests suite

git clone git@github.com:Nekland/Woketo
cd Woketo
composer install
./bin/phpunit

Functionnal tests suite

Server test suite

php tests/echo-server.php
wstest -m fuzzingclient

Client test suite

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 something else?

  • 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.

What's next?

You can see what's planned for next versions in the github milestones.

What Woketo does not do?

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.

Thanks

Thank you to all code contributors (Hello folliked =)). And to any code reviewer (Hi valanz).

<3