Why do Websockets only function on Google Chrome and is there an alternative that works on all browsers?
Websockets only function on Google Chrome because it was the first browser to fully support the Websockets protocol. To make Websockets work on all browsers, you can use a library like Socket.io which provides a fallback mechanism to use other transport protocols if Websockets are not supported.
// Install the Socket.io library using Composer
composer require cboden/ratchet
// Create a new Socket.io server
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use YourApp\YourWebSocketServer;
$server = IoServer::factory(
new HttpServer(
new WsServer(
new YourWebSocketServer()
)
),
8080
);
$server->run();