承接 fanout/pubcontrol 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fanout/pubcontrol

最新稳定版本:2.3.0

Composer 安装命令:

composer require fanout/pubcontrol

包简介

A PHP convenience library for publishing messages using the EPCP protocol.

README 文档

README

Author: Konstantin Bokarius kon@fanout.io

EPCP library for PHP.

License

php-pubcontrol is offered under the MIT license. See the LICENSE file.

Requirements

  • openssl
  • curl
  • pthreads (required for asynchronous publishing)
  • firebase/php-jwt >=1.0.0 (retreived automatically via Composer)

Installation

Using Composer: 'composer require fanout/pubcontrol'

Manual: ensure that php-jwt has been included and require the following files in php-pubcontrol:

require 'php-pubcontrol/src/format.php';
require 'php-pubcontrol/src/item.php';
require 'php-pubcontrol/src/pubcontrolclient.php';
require 'php-pubcontrol/src/pubcontrol.php';

Asynchronous Publishing

In order to make asynchronous publish calls pthreads must be installed. If pthreads is not installed then only synchronous publish calls can be made. To install pthreads recompile PHP with the following flag: '--enable-maintainer-zts'

Also note that since a callback passed to the publish_async methods is going to be executed in a separate thread, that callback and the class it belongs to are subject to the rules and limitations imposed by the pthreads extension.

See more information about pthreads here: http://php.net/manual/en/book.pthreads.php

Usage

<?php

class HttpResponseFormat extends PubControl\Format
{
    private $body = null;

    public function __construct($body)
    {
        $this->body = $body;
    }

	function name()
    { 
        return 'http-response';
    }

	function export()
    {
        return array('body' => $this->body);
    }
}

function callback($result, $message)
{
    if ($result)
        Print "Publish successful\r\n";
    else
        Print "Publish failed with message: {$message}\r\n";
}

// PubControl can be initialized with or without an endpoint configuration.
// Each endpoint can include optional JWT authentication info.
// Multiple endpoints can be included in a single configuration.

// Initialize PubControl with a single endpoint:
$pub = new PubControl\PubControl(array(
        'uri' => 'https://api.fanout.io/realm/<myrealm>',
        'iss' => '<myrealm>', 'key' => base64_decode('<realmkey>')));

// Add new endpoints by applying an endpoint configuration:
$pub->apply_config(array(array('uri' => '<myendpoint_uri_1>'), 
        array('uri' => '<myendpoint_uri_2>')));

// Remove all configured endpoints:
$pub->remove_all_clients();

// Explicitly add an endpoint as a PubControlClient instance:
$pubclient = new PubControl\PubControlClient('<myendpoint_uri>');
// Optionally set JWT auth: $pubclient->set_auth_jwt(<claim>, '<key>');
// Optionally set basic auth: $pubclient->set_auth_basic('<user>', '<password>');
$pub->add_client($pubclient);

// Publish across all configured endpoints synchronously:
$pub->publish('<channel>', new PubControl\Item(
        new HttpResponseFormat("Test publish!")));

// Use publish_async for async publishing only if pthreads are installed:
// if ($pub->is_async_supported())
//     $pub->publish_async('<channel>', new PubControl\Item(
//     new HttpResponseFormat("Test async publish!")));
// Wait for all async publish calls to complete:
// $pub->finish();
?>

统计信息

  • 总下载量: 102.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 7
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-17