不需要have美元.
Those pieces of software just happen to make it trivial to work with the Websocket protocol.
Remember, Laravel is an opinionated framework. This means that it will pick and choose its own libraries to abstract away these kinds of concepts for you so that you don't have to worry so much about what's going on under the hood.
基本上,您需要两个组件才能使用WebSocket:
- A Websocket Server
- A Websocket Client
Laravel不使用Websocket直接与前端通信的原因是,Laravel本身不是Websocket服务器.至少,不是真的.虽然PHP确实支持使用Websocket协议-and even some libraries to leverage it a little more nicely,但它并不像其他语言那样经常用于处理长生命周期 的进程.
取而代之的是,Laravel使用Pub/Sub functionality that Redis provides来监听通过Redis和Predis library发生的事件.之所以这样做,是因为Larvel更适合作为websocket服务器和所有连接客户端的中间人.
In this way, Laravel can both pass information up through to the Websocket server using Broadcasting Events, as well as receive event information from the Websocket server and determine if users have the ability or authorization to receive them.
If you don't want to use Pusher, there is a library that will allow you to run your own Websocket Server specifically for Laravel called Laravel Echo Server.
Under the hood, this library still uses Socket.io and Redis in order for all moving parts to communicate with each other seamlessly in a Laravel web application. The benefit here is that you won't need to worry about the number of messages being sent by the server.
The downside is that you now have to know how to manage and maintain this process on your server so that the Websocket Server will know to turn on every time you restart your server, or if a failure happens, etc.
Check out PM2 to learn more about running and maintaining server daemons.
如果您不同意Laravel关于如何处理WebSocket的观点,那么理论上您可以使用任何其他服务器端语言来处理WebSocket协议.它只需要更多关于协议本身的工作知识;如果Laravel需要使用它,您必须知道如何编写适当的Service和Provider类来处理它.