定制 fervo/deferred-event-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

fervo/deferred-event-bundle

Composer 安装命令:

composer require fervo/deferred-event-bundle

包简介

Defer your events to another process (via FastCGI)

README 文档

README

This bundle allows you to run asynchronous background processes in PHP. You don't need a PHP-daemon nor do you have to create a new php process for each job (which is expensive). We use PHP-FPM because it solves the performance and stability issues for us.

I wrote a blog entry with the reasoning behind this bundle, which you may want to read.

Caveat

This project is no longer actively developed by Fervo. We're still willing to merge PRs, but we're moving away from this internally. If you have a vested interest in this project and want to adopt it, contact us at magnus@fervo.se.

Usage

You can defer events in two ways. You can decide when you dispatch an event that it should be deferred or you could let some listeners to decide if they should be deferred or not. In both cases we dispatch the event and put the job on a message queue.

As if by magic, at some later time, a worker will dispatch your event to your listeners. Pretty much the only caveats you'll need to keep in mind is that it is in another process, and that the code isn't executing in the request scope anymore.

Let the listeners decide

Just tag your listener with fervo_deferred_event.listener instead of kernel.event_listener, and the bundle will do the rest. Simple as pie.

Let the publisher decide

If you want all listeners to a event to be executed in a different thread you must wrap your Event in a DeferEvent. Then use the event dispatcher and dispatch 'fervo.defer'.

$event = new DeferEvent('foo.action', new MyEvent());
$this->get('event_dispatcher')->dispatch('fervo.defer', $event);

Setup

Server software

You need to install a message queue and a worker. The worker will pull jobs from the message queue and initiate the execution.

Currently we do support all message queues that support AMQP and Sidekiq.

Here is a list of workers:

Symfony setup

Add the bundle to your composer file, as well as well as your AppKernel. Configure the bundle as follows:

# Sidekiq example
fervo_deferred_event:
    backend:
        type: sidekiq
        sidekiq_client_service: sidekiq_client

# Java/AMQP example:
fervo_deferred_event:
    backend:
        type: amqp
        amqp_config:
            host: "localhost"             #default
            port: 5672                    #default
            batch_publishing: false       #can only be true if you are using videlalvaro/php-amqplib v.2.2.0 or above
        message_headers:
            fastcgi_host: "localhost"     #default
            fastcgi_port: 9000            #default

You do also need to setup one of the following (depending on you backend type):

Error handling

The Java worker we take care of errors. When a worker unexpectedly terminates we will save the message and the error message on a separate queue. You may subscribe to that queue to log the error and to retry executing the job.

fervo/deferred-event-bundle 适用场景与选型建议

fervo/deferred-event-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 93.46k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2013 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 fervo/deferred-event-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fervo/deferred-event-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 fervo/deferred-event-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 43
  • Watchers: 9
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-11-25