承接 shankao/daemonizer 相关项目开发

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

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

shankao/daemonizer

Composer 安装命令:

composer require shankao/daemonizer

包简介

README 文档

README

This project aims to greatly simplify the creation of very lightweight system daemons in PHP, and hide the low-level details after a modern class-based interface.

Daemonizer implements a fast and simple main loop for you, so you don't need to take care of the details. A disadvantage of this is that you must let your class' run() function end from time to time (no infinite loops). Failing to do this will make your daemon unresponsive to external signals (i.e. sigterm)

Daemonizer uses a version of PEAR's System_Daemon internally. Find it here: kvz/system_daemon

A very simple example

Daemon that echoes a string once per second:

class example implements Daemonizer\Daemonizable {
  public function sleep_time() {
    return 1; // In seconds
  }
  
  public function run() {
    echo "Hey there!\n";
  }
}

$daemon = new Daemonizer\Daemonizer('example', '././example/example.pid');
// Add customizations. I.e: $daemon->set_logfn('my_logging_function');
$daemon->run(new example);

Find a sightly more complete example at https://github.com/shankao/Daemonizer/blob/master/example.php

About the PID location parameter

Sadly, using System_Daemon internally has its drawbacks. One of the most visible in Daemonizer is the way that the PID file location has to be indicated:

  1. It requires to have at least two backslashes to start. In our example, the first part of "././example/example.pid" is only used to refer to the current folder. This requirement is due to System_Daemon expecting PID's to be system-wide located, like in /var/run (see the two backslashes)
  2. It requires that, after the two slashes, comes a folder with the same name as the daemon's name. In the example before, the "example" folder part. The reason is the same: System_Daemon requires to follow a UNIX system-wide protocol for PID file locations.

This problems will be fixed with the depart from System_Daemon in the future

Customization functions

Call them for your Daemonizer object, before the call to run() to change some aspects of the daemon:

set_finishfn(callable $fn)

Set the function to call when the daemon receives a SIGTERM signal

set_restartfn(callable $fn)

Set the function to call when the daemon receives a SIGHUP signal

set_uid(int)

Force the daemon's UID to this one

set_gid(int)

Force the daemon's GID to this one

set_logfn(callable $fn)

Set the function to call for logging

set_loglevel(int)

Set System_Daemon's logging level

Next steps

For next releases, I intend to keep the same functionality, without using System_Daemon internally, as its code has become old and bloated. Given that I intend to keep Daemonizer simple and lightweight, that last part is not good. Also, the PID location quirk is painful for a real-world project.

shankao/daemonizer 适用场景与选型建议

shankao/daemonizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 shankao/daemonizer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-11-27