承接 andersundsehr/server-send-events 相关项目开发

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

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

andersundsehr/server-send-events

最新稳定版本:1.0.4

Composer 安装命令:

composer require andersundsehr/server-send-events

包简介

Utility Package to help with the creation of text/event-stream

README 文档

README

install

composer req andersundsehr/server-send-events

what does it do

it makes it easy to use the text/event-stream (Server Send Events).

inside your Controller:

if (ServerSendEventStream::isEventStream($this->request)) {
    $stream = new ServerSendEventStream();
    $trigger = new FileEventTrigger($stream);

    $stopTime = time() + (5 * 60);
    do {
        $stream->sendMessage($this->getInfo()); // is send to the JS long running script

        $trigger->sleepUntilTrigger('changed-' . $currentUser->getUid(), $stopTime);
    } while (time() < $stopTime);
    die();
}

somewhere else in the code:

(new FileEventTrigger())->trigger('changed-' . $currentUser->getUid());

in your JS

//EventSource as an auto restart :)
const evtSource = new EventSource(url, {
  withCredentials: true,
});
evtSource.addEventListener("message", (e) => {
  const data = JSON.parse(e.data);
  // do stuff with the data
  // data comes from $stream->sendMessage()
});

with ♥️ from anders und sehr GmbH

If something did not work 😮
or you appreciate this Extension 🥰 let us know.

We are hiring https://www.andersundsehr.com/karriere/

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-06-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固