phpgt/daemon
Composer 安装命令:
composer require phpgt/daemon
包简介
Background script execution with cross-platform compatible streaming.
README 文档
README
Execute background processes asynchronously using an object oriented process pool.
Example usage
<?php use GT\Daemon\Process; use GT\Daemon\Pool; // Create three long-running processes: $pingProcess = new Process("ping google.com"); $infiniteProcess = new Process("while true; do echo 'background...'; sleep 3; done"); $dateProcess = new Process("while true; do echo $(date -d now); sleep 2; done"); // Add all three processes to a pool: $pool = new Pool(); $pool->add("Ping", $pingProcess); $pool->add("Loop", $infiniteProcess); $pool->add("Date", $dateProcess); // Start the execution of all processes: $pool->exec(); // While processes are running, write their output to the terminal: do { echo $pool->read(); // Sleep to avoid hogging the CPU. sleep(1); } while($pool->numRunning() > 0);
Outputs something similar to:
[Ping] PING google.com (172.217.169.78) 56(84) bytes of data.
[Ping] 64 bytes from lhr48s09-in-f14.1e100.net (172.217.169.78): icmp_seq=1 ttl=52 time=8.78 ms
[Loop] background...
[Date] Mon 19 Aug 09:58:54 BST 2019
[Ping] 64 bytes from lhr48s09-in-f14.1e100.net (172.217.169.78): icmp_seq=2 ttl=52 time=8.75 ms
[Ping] 64 bytes from lhr48s09-in-f14.1e100.net (172.217.169.78): icmp_seq=3 ttl=52 time=8.75 ms
[Date] Mon 19 Aug 09:58:56 BST 2019
[Ping] 64 bytes from lhr48s09-in-f14.1e100.net (172.217.169.78): icmp_seq=4 ttl=52 time=8.75 ms
[Loop] background...
[Ping] 64 bytes from lhr48s09-in-f14.1e100.net (172.217.169.78): icmp_seq=5 ttl=52 time=8.80 ms
[Date] Mon 19 Aug 09:58:58 BST 2019
Notice how the date process is only set to loop three times, and after it is complete the other two infinite processes continue to run.
Proudly sponsored by
phpgt/daemon 适用场景与选型建议
phpgt/daemon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.13k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phpgt/daemon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpgt/daemon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-04-03