Вопрос

I am trying to get a Ratchet WebSocket server running that has access to DataObjects from a SilverStripe instance that can be run as a long-running process from the terminal.

My current approach, taking the lead from cli-script.php is to include core/Core.php and model/DB.php and connect to the database using the same database config as is defined in _config.php

Is there a better way of doing this that doesn't involve copying code from cli-script.php? The only though I had was a controller that fires up the server but that sounds wrong too.

Another thought was to keep them separate and use the SS REST API to interact between them but it would be simpler to interact with the PHP objects instead.

Это было полезно?

Решение

In the end, I turned the design on it's head and had all the messages go via the SilverStripe instance (Ajax from the client), which then pushed WebSocket messages out over a REST API.

When looking into hosting for such a process, I stumbled upon Pusher, which I am now using for the real-time aspect of the system.

In short:

  1. A JS client informs the SilverStripe app of a change using Ajax.
  2. The SilverStripe app persists the change in the database.
  3. The SilverStripe app pushes a message via Pusher using their API / PHP library.
  4. Pusher sends the message over a WebSocket connection to all other connected clients.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top