ereborcodeforge/mithrilexecutor

A library to execute scripts and files in the background seamlessly, providing an simple and easy-to-use interface for managing background processes in PHP.

v1.1.0 2024-09-13 19:31 UTC

This package is auto-updated.

Last update: 2025-06-19 18:49:23 UTC


README

MithrilExecutor is a PHP library that facilitates the execution of background tasks. It allows you to run PHP files or instantiate classes, execute methods in a defined order, and capture logs and return values from the referenced methods. With MithrilExecutor, you can schedule task execution and process them asynchronously, making it ideal for long-running or intensive operations.

Installation

You can install MithrilExecutor via Composer. Run the following command in your terminal:


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

Example: passing a file as a reference

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