承接 eislambey/eventsource 相关项目开发

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

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

eislambey/eventsource

最新稳定版本:v0.1.0

Composer 安装命令:

composer require eislambey/eventsource

包简介

A simple EventSource / SSE (Server-Sent Events) client.

README 文档

README

A Simple EventSource / SSE (Server-Sent Events) client for PHP.

Installation

$ composer require eislambey/eventsource

Usage

Example: Connect to an endpoint and read 5 messages then close.

<?php

require_once dir(__FILE__) . '/vendor/autoload.php';

use EventSource\Event;
use EventSource\EventSource;

$es = new EventSource("http://example.com");
$messageReceived = 0;
$es->onMessage(function (Event $event) use(&$messageReceived, $es) {
    if($es === 4){
        $es->abort();
    }
    $messageReceived++;

    echo $event->data, "\n";
});

$es->connect();

Methods

__construct(string $url)

Create new instance with the given url.

onMessage(callable $fn): void

Set a function that called when a message is received.

connect(): void

Connect to endpoint and receive messages.

abort(): void

Abort the connection and stop receiving messages.

setCurlOptions(array $options): void

You can set any cURL options (such as cookies and headers) excluding CURLOPT_WRITEFUNCTION, CURLOPT_NOPROGRESS, CURLOPT_PROGRESSFUNCTION.

See: https://www.php.net/manual/tr/function.curl-setopt.php

LICENSE

The MIT License (MIT). Please see LICENSE for more information.

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-07