terremoth/php-async
Composer 安装命令:
composer require terremoth/php-async
包简介
Write async PHP processes or process async files with no phtreads, parallel or reactive libs
README 文档
README
Process functions or files async and in parallel without needing AMP, ReactPHP, RxPHP, Spatie/Fork, Fibers, Pthreads, Parallel, Revolt, Pcntl or Swoole.
Just raw PHP! It is magic! This is not the classical meaning of async like python's or nodejs you're addicted to hear. This is more like an "Async Process", or "Async Multitasking", but you can achieve the same results you expect. Enjoy.
Target Audience
For those who, for some reason, cannot or don't want to use Swoole or Parallel
Why?
- Native way + no need to change php.ini
- Easy: just composer install the lib and use it
- Fast to learn
- Fast to use: no need to compile, no need to download pecl extensions
- Operating system agnostic
How?
It uses a combination of:
- serializable-clojure lib
- Symfony/Process lib
- and PHP's native Shmop extension (available in any platform)
First it serializes your closure with its code,
Then it sends to another background process to execute, through shmop
Some Possible Use Cases
- You got some user data and want to do a heavy processing somewhere without blocking;
- You want to send an email in your own platform without blocking with some data you got before;
- You want to create tons of processes at the same time, not blocking the main process/thread;
- Something will be heavy processed and will took time but your user does not need to know that at the time and don't need/want to wait;
Warning
it does not works on MSYS or MINGW shells! However, It will work fine on both Windows (cmd and powershell) and Linux.
See demos/demo.php for examples.
Installation
composer require terremoth/php-async
Documentation
<?php require_once 'vendor/autoload.php'; use Terremoth\Async\PhpFile; use Terremoth\Async\Process; $process = new Process(); $age = 30; $name = 'John Doe'; $fruits = ['orange', 'apple', 'grape']; $process->send(function () use ($age, $name, $fruits) { /* // Anything you want to process here // + you can use closure vars for sending data to the other process */ }); // Another way to use is if you want to just process a file Asynchronously, you can do this: $args = ['--verbose', '-n', '123']; $asyncFile = new PhpFile('existing-php-file.php', $args); // make sure to pass the correct file with its path $asyncFile->run(); /* Take care with $args if you will use it this way! Attackers may explore this to inject commands through RFI/LFI attacks. The suggestion is: avoid the users to add/control the $args variable. */
terremoth/php-async 适用场景与选型建议
terremoth/php-async 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 33, 最近一次更新时间为 2024 年 12 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「async」 「async-process」 「parallel-processing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 terremoth/php-async 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 terremoth/php-async 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 terremoth/php-async 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tool for managing fast both asynchronous and multi-threaded execution of tasks. Focused on performance and pleasant CLI interface.
Configurable parallel PHP code analyzer for checking class references
The bundle for easy using json-rpc api on your project
An async event for hyperf.
Zenity allows you to build graphical desktop (GUI) applications in PHP, built on top of ReactPHP.
Async Curl using React\ChildProcess
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 33
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-12-01