Black Friday Week - This week only! Black Friday Week - Save up to 50% on our courses and apps. Learn more
When your application is ready to get deployed, here are some tips to improve your WebSocket server.
On Unix systems, every user that connects to your WebSocket server is represented as a file somewhere on the system. As a security measurement of every Unix based OS, the number of "file descriptors" an application may have open at a time is limited - most of the time to a default value of 1024 - which would result in a maximum number of 1024 concurrent users on your WebSocket server.
In addition to the OS restrictions, this package makes use of an event loop called "stream_select", which has a hard limit of 1024.
The operating system limit of open "file descriptors" can be increased using the
ulimit command. The
-n option modifies the number of open file descriptors.
ulimit -n 10000
ulimit command only temporarily increases the maximum number of open file descriptors. To permanently modify this value, you can edit it in your operating system
You are best to do so by creating a file in the
limits.d directory. This will work for both Red Hat & Ubuntu derivatives.
$ cat /etc/security/limits.d/laravel-echo.conf laravel-echo soft nofile 10000
The above example assumes you will run your echo server as the
laravel-echo user, you are free to change that to your liking.
To make use of a different event loop, that does not have a hard limit of 1024 concurrent connections, you can either install the
event PECL extension using:
sudo pecl install ev # or sudo pecl install event