

In a typical PHP application you don’t need that because the collection or the data structure are accessed by a single thread.

Swoole Table is a data structure similar to a collection (bi dimensional array), that allows to manage multiple concurrent thread that want to add, remove, retrieve items. The server will keep track of the connected client via the Swoole Table. The closing of the connection by the client, implies the invalidation of its specific connection Close: when a client closes the connection.Connections initialized with "Open" remain active and are persistent

Message: when a message arrives from one of the active connections.Open: when a new connection request from a new client arrives.Start: when the server side WebSocket part is started.On the server side, we are going to implement a WebSocket service on TCP protocol that listens and reacts to some very specific events: To do this, we are going to use "Swoole WebSocket Server" based on TCP protocol and with secure WebSocket (communication over network is encrypted, a bit like HTTP and HTTPS). We have a server side service, implemented with PHP and Open Swoole. The connection between the client and the server is persistent and allows for a two-way conversation for multiple messages.īefore we get to the code, let me explain the example application we're going to implement. The server will forward or will send messages to the client. A client can connect with the server side part, and if a client wants to communicate with other clients, it can do it by sending messages to the server. In a WebSocket "scenario" you have a server-side part and multiple clients.

A flow of this type is not persistent and is strongly controlled from the client. The client, if it needs a further resource, starts again a request. The server once provided the resource closes the connection. This scenario is very simple: the client (the browser) makes a request (GET or POST or PUT.) for a specific resource. Requests of this type are not persistent and are stateless. The typical usage of PHP is as a server-side language for responding to HTTP requests.
