Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

PubSub Server Setup

Hunter Perrin edited this page May 8, 2018 · 4 revisions

App Template Setup

You can use the app template to set up Nymph and Nymph PubSub for you. All you need to install is Docker.

Nymph App Template

Manual Setup

You can manually set up Nymph PubSub if you don't want to use the app template. Once you've followed the instructions for setting up a Nymph server, you're ready to set up a PubSub server.

Setting up a Nymph PubSub server is very similar to setting up the REST endpoint. One key difference is that you must run the PHP file you create in order to run the server. Nymph PubSub does not use your web server to accept connections. It opens its own port to accept WebSocket connections.

Create a file which you will run to launch your PubSub server. In the nymph-examples repo, it is named pubsub.php. Add anything you need to configure Nymph.

Before you start setting everything up, you should make sure the file was called from the command line.

if (php_sapi_name() != "cli") {
  die("You can only run pubsub.php from the command line.");
}

The first step is to create your config array. You can see the available configuration options in the PubSub defaults file.

$config = [
  'port' => 8080
];

Make sure Nymph is connected, and load all of the classes you'll need (unless you're using an autoloader).

\Nymph\Nymph::connect();
require 'MyEntity.php';
require 'MyOtherEntity.php';

Now create and run the server loop.

$server = new \Nymph\PubSub\Server($config);
$server->run();

You can look in the example PubSub server to see how to make this process a daemon.

Clone this wiki locally