sciactive/nymph-pubsub

该软件包已被废弃且不再维护。没有建议的替代软件包。

用于发布/订阅 Nymph 数据库变化的库。


README

Latest Stable Version Open Issues License

用于协作网络应用的强大对象数据存储和查询。

弃用通知

Nymph/Tilmeld 的 PHP 实现已被弃用。它将不再添加任何新功能。取而代之的是,将使用 TypeScript 编写的 Node.js 新版本 Nymph 替换 PHP 实现。您可以在 Nymph.js 仓库 中找到它。

安装

自动设置

开始构建 Nymph 应用最快的方法是使用 Nymph 应用模板

手动安装

composer require sciactive/nymph-pubsub

该仓库是 PHP 发布/订阅服务器。有关更多信息,请参阅 主要 Nymph 仓库

用法

// pubsub.php: Start with `php pubsub.php [-d]`

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

// This is an example server that is configured with hostname
// "pubsubnetwork1entry" as an entry point to network1, which contains two
// endpoint servers, "pubsubnetwork1endpoint1" and "pubsubnetwork1endpoint2".

// Setting a default timezome is highly recommended.
date_default_timezone_set('America/Los_Angeles');

require 'vendor/autoload.php';

// Set up Nymph.
use Nymph\Nymph;
Nymph::configure([
  'MySQL' => [
    'host' => 'your_db_host',
    'database' => 'your_database',
    'user' => 'your_user',
    'password' => 'your_password'
  ]
]);

\Nymph\Nymph::connect();

// Allow this file to be called with "-d" to daemonize it.
if (in_array('-d', $argv)) {
  function shutdown() {
    posix_kill(posix_getpid(), SIGHUP);
  }

  // Switch over to daemon mode.
  if ($pid = pcntl_fork()) {
    return;
  }

  register_shutdown_function('shutdown');
} else {
  error_reporting(E_ALL);
}

// Set up Nymph PubSub.
$config = include(__DIR__.'/pubsub-config.php');
$config['port'] = 8080;
$config['relays'] = [
  'ws://pubsubnetwork1endpoint1:8080/',
  'ws://pubsubnetwork1endpoint2:8080/'
];
$server = new \Nymph\PubSub\Server($config);

// Run the server.
$server->run();
// pubsub-config.php

// This config file tells Nymph to publish entity updates to these network entry
// points. They will then relay the publish to their network.

return [
  'entries' => [
    'ws://pubsubnetwork1entry:8080/',
    'ws://pubsubnetwork2entry:8080/',
    'ws://pubsubnetwork3entry:8080/'
  ]
];
// somewhere in your Nymph rest endpoint.
$config = include('path/to/pubsub/pubsub-config.php');
\Nymph\PubSub\Server::configure($config);

有关在您的服务器上设置 Nymph 的详细步骤指南,请访问 设置指南

API 文档

查看维基中的 API 文档