I integrated Websocket in my wordpress website(in a plugin) and when i launch it all other requests are blocked since the $server->run method is a loop. Any suggestion to fix it please ?
<?php
namespace Phenix\API\WebSocket;
use Ratchet\App;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class WebSocket_Server implements MessageComponentInterface
{
public function onOpen(ConnectionInterface $conn)
{
}
public function onMessage(ConnectionInterface $from, $msg)
{
}
public function onClose(ConnectionInterface $conn)
{
}
public function onError(ConnectionInterface $conn, \Exception $e)
{
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
try {
$server = new App("192.168.1.121", 3000, "192.168.1.121",); $server->route('/ws', new WebSocket_Server(), ['*']);
} catch (\Exception $e) {
error_log($e->getMessage() . PHP_EOL, 3, DEBUG_LOGS_FILE);
}
View all comments
Show parent comment
1
u/MateusAzevedo Dec 26 '24
I don't think that's the correct approach. The websocket server is a server by itself, a long running process that you don't want to tie to http and block php-fpm/apache process.