Quick Start

Home » Documentation » Quick Start

The most profound technologies are those that disappear. They weave themselves into the fabric of everyday life until they are indistinguishable from it.

Mark Weiser

After installation, let’s start with the simplest case: ping/pong with the server.

The following file run an OpenSwoole WebSocket server:

<?php

// server.php

use Conveyor\ConveyorServer;

ConveyorServer::start(port: 8080);

Important: notice that handling the “handshake” event might be necessary; for reference, visit: https://openswoole.com/docs/modules/swoole-websocket-server-on-handshake.

Then you run:

# shell
php server.php

Once this is running, you should be able to connect to it using base Websocket client or any of the clients built for Socket Conveyor. The following is an example using the raw JavaScript Websocket object:

<script type="text/javascript">
    let ws = new WebSocket(`ws://127.0.0.1:8080`)

    ws.onmessage = (e) => console.log(e)

    ws.onopen = () => {
        // connect to channel
        ws.send(JSON.stringify({ action: 'channel-connect', channel: 'my-channel' }))

        // broadcast to "my-channel"
        ws.send(JSON.stringify({ action: 'broadcast-action', data: 'My broadcast message.' }))
    }
</script>

This client will connect to the WebSocket server, then it will connect to a channel and broadcast a message to it.

To learn more about the available actions in Socket Conveyor, you can find it here: Available Actions.

This is a very basic client connection. Conveyor comes with some client packages in PHP and JavaScript with which you can use all the features of Conveyor, making sure to keep all the best practices – or you can check their source code and help make them better.