Ligonsker's avatar

Using Laravel Websockets - as a separate project, or inside a project?

Hello, I am planning to use Laravel Websockets. I have 3 projects right now and right now only 1 of them needs to use it but I believe more will need it in the future.

Should I create it inside one of the projects, or set it up as a separate project that will act as the websockets server?

There are 3 options:

  1. Use it in the current project I need, and if other projects will use it in the future, use the same instance of the websockets server as seen in the docs: https://beyondco.de/docs/laravel-websockets/basic-usage/pusher#configuring-websocket-apps

  2. For each project, install a new Laravel Websockets server that will work on different ports (6001, 6002, 6003 for example).

  3. Create a separate Laravel-Websockets project that will handle the multi-tenancy instead of inside one of the projects

Or something else?

Thanks

0 likes
2 replies
LaryAI's avatar
Level 58

In this scenario, it would be best to create a separate Laravel-Websockets project that will handle the multi-tenancy instead of inside one of the projects. This approach will allow you to have a centralized location for managing your websockets server, and it will be easier to scale in the future if more projects need to use it.

To set up a separate Laravel-Websockets project, you can follow the installation instructions provided in the Laravel-Websockets documentation. Once you have the server up and running, you can configure your other projects to use it by updating the BROADCAST_DRIVER setting in your .env file to pusher, and then configuring the PUSHER_APP_ID, PUSHER_APP_KEY, and PUSHER_APP_SECRET settings to match the values for your Laravel-Websockets server.

Here's an example of how you can configure your .env file to use a separate Laravel-Websockets server:

BROADCAST_DRIVER=pusher

PUSHER_APP_ID=your-app-id
PUSHER_APP_KEY=your-app-key
PUSHER_APP_SECRET=your-app-secret
PUSHER_APP_CLUSTER=mt1

PUSHER_HOST=your-websockets-server-host
PUSHER_PORT=6001
PUSHER_SCHEME=http

Note that you'll need to replace the your-app-id, your-app-key, and your-app-secret values with the appropriate values for your Laravel-Websockets server, and update the your-websockets-server-host value to match the hostname or IP address of your server.

By using a separate Laravel-Websockets project, you'll be able to easily manage your websockets server and scale it as needed in the future.

Ligonsker's avatar

Does anyone knows what happens in case one of the apps needs more websocket usage to the point it bogs down the server? In this case where I have 1 server that runs on the same port, it is not possible to actually separate projects, so how can I do it?

Please or to participate in this conversation.