ereborcodeforge / mithrilexecutor
MithrilExecutor 是一个在后台无缝执行脚本和文件的库,为管理 PHP 中的后台进程提供了一个简单易用的界面。
v1.1.0
2024-09-13 19:31 UTC
Requires (Dev)
- phpunit/phpunit: ^11.3
This package is auto-updated.
Last update: 2024-09-19 17:14:44 UTC
README
MithrilExecutor 是一个 PHP 库,它简化了后台任务的执行。它允许您运行 PHP 文件或实例化类,按定义的顺序执行方法,并从引用的方法捕获日志和返回值。使用 MithrilExecutor,您可以安排任务执行并异步处理,非常适合长时间运行或密集型操作。
安装
您可以通过 Composer 安装 MithrilExecutor。在您的终端运行以下命令
composer require ereborcodeforge/mithrilexecutor ##Example: passing an instance as a reference ```bash use MithrilExecutor\BackgroundExecutor; $backgroundInstance = new BackgroundExecutor(); $outputResult = $backgroundInstance ->withConstruct(TestClass::class) // Instantiates the class to be executed ->addMethod('clearLog') // Adds the 'clearLog' method for execution ->addMethod('fetchDataAndLog') // Adds the 'fetchDataAndLog' method for execution ->addMethod('getLog') // Adds the 'getLog' method for execution ->runNow() // Executes the methods in the background ->getOutPuts(); // Returns the output results
示例:传递一个文件作为引用
use MithrilExecutor\BackgroundExecutor; $backgroundInstance = new BackgroundExecutor(); $outputResult = $backgroundInstance ->withFile('/path/to/script.php', 'ClassName') // Defines the PHP file to be executed ->addMethod('clearLog') // Adds the 'clearLog' method for execution ->addMethod('fetchDataAndLog') // Adds the 'fetchDataAndLog' method for execution ->addMethod('getLog') // Adds the 'getLog' method for execution ->runNow() // Executes the methods in the background ->getOutPuts(); // Returns the output results