Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Is there an equivalent of soketi for Window Server?

Hello,

Is it possible to setup a local web sockets server that works well with Laravel on a Windows Server like soketi? I have a local project with soketi and it works well, but what are my options if I need it on a Windows Server?

Thanks!

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, there are several options for setting up a local web sockets server on a Windows Server that works well with Laravel. One popular option is to use the Ratchet library, which is a PHP library for creating real-time, bi-directional applications like chat rooms, games, and live feeds.

To use Ratchet with Laravel, you can follow these steps:

  1. Install Ratchet using Composer:
composer require cboden/ratchet
  1. Create a new Ratchet server class that extends the Ratchet\MessageComponentInterface interface. This class will handle incoming WebSocket connections and messages. Here's an example:
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class MyWebSocketServer implements MessageComponentInterface
{
    protected $clients;

    public function __construct()
    {
        $this->clients = new \SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn)
    {
        $this->clients->attach($conn);
        echo "New connection! ({$conn->resourceId})\n";
    }

    public function onMessage(ConnectionInterface $from, $msg)
    {
        foreach ($this->clients as $client) {
            if ($client !== $from) {
                $client->send($msg);
            }
        }
    }

    public function onClose(ConnectionInterface $conn)
    {
        $this->clients->detach($conn);
        echo "Connection {$conn->resourceId} has disconnected\n";
    }

    public function onError(ConnectionInterface $conn, \Exception $e)
    {
        echo "An error has occurred: {$e->getMessage()}\n";
        $conn->close();
    }
}
  1. Create a new Laravel command that starts the Ratchet server. Here's an example:
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;

class StartWebSocketServer extends Command
{
    protected $signature = 'websocket:serve';
    protected $description = 'Start the WebSocket server';

    public function handle()
    {
        $server = IoServer::factory(
            new HttpServer(
                new WsServer(
                    new MyWebSocketServer()
                )
            ),
            8080
        );

        $server->run();
    }
}
  1. Run the command to start the WebSocket server:
php artisan websocket:serve

Now you can connect to the WebSocket server using a WebSocket client, such as a JavaScript client in your Laravel application. For example:

var conn = new WebSocket('ws://localhost:8080');

conn.onopen = function() {
    console.log('Connected to WebSocket server');
};

conn.onmessage = function(e) {
    console.log('Received message: ' + e.data);
};

conn.onclose = function() {
    console.log('Disconnected from WebSocket server');
};

Note that you may need to configure your Windows Server firewall to allow incoming connections on port 8080.

Please or to participate in this conversation.