Download the PHP package jumaphelix/php-dag without Composer
On this page you can find all versions of the php package jumaphelix/php-dag. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jumaphelix/php-dag
More information about jumaphelix/php-dag
Files in jumaphelix/php-dag
Package php-dag
Short Description Implementation of Directed Acyclic Graphs (DAG) based task executions with parallelization in PHP
License MIT
Informations about the package php-dag
PHP Directed Acyclic Graphs (DAG)
- Implementation of Directed Acyclic Graphs (DAG) based task executions with parallelization in PHP
- When you have a set of tasks you want to execute but some tasks have dependencies, meaning they should only run after their dependencies have completed, then this is the package for you.
- The tasks are first resolved based on their dependencies and are executed in parallel using Swoole. Tasks can get output from their dependencies in case they rely on that data for their executions.
- You can also use this package directly as a way to parallelize execution of synchronous tasks.
REQUIREMENTS
- PHP >= 8.1
- Swoole: This package only works after you have installed Swoole extension and enabled the extension in your php.ini configuration file.
INSTALLATION
USAGE
Consider a set of 5 tasks A,B,C,D and E such that task A can only run after task D and B after C: C -> B D -> A E For this case, tasks C, D and E can be executed concurrently while task A should only start as soon as D completes and task B should also only start as soon as task C completes.
DAG Topological Sort
We can represent these tasks as a DAG as long as there are no cyclic dependencies and then sort the tasks in order of execution based on the given information
Task Execution with Dependencies
Let's see a sample example of the above case with simple task implementations
Basic Parallelization
Assume you just want to parallelize tasks that have no dependencies. For instance, I need to loop 1 thousand records from a database and do an operation that takes 1 second in each, the total time will be 1000 seconds, if the loop runs normally in PHP. We can parallelize the execution such that the total time remains 1 second irrespective of the number of records.