PHP Classes

PHP Async Executor: Run PHP scripts in parallel using the CLI version

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 146 All time: 9,128 This week: 104Up
Version License PHP version Categories
asyncexecutor 7GNU General Publi...5Tools, Files and Folders, Unix, Console, L..., P...


This package can run PHP scripts in parallel using the CLI version.

It can run a given PHP script by executing the PHP CLI version. It passes the name of the script and the parameter values as command line parameter values.

The package may start a process to run an existing script file. It may also wait a given time if the script file does not exist, allowing another process to create the script file while the package waits.

Innovation Award
PHP Programming Innovation award nominee
June 2021
Number 6
One way to run multiple PHP scripts simultaneously is to use the PHP CLI version and start it as a parallel process. The start is a bit slow because a new program needs to be loaded.

To start faster, this package provides a solution that can start the parallel process first before creating the actual script that the process will run.

Manuel Lemos
Picture of Alexandre Sinício
  Performance   Level  
Name: Alexandre Sinício <contact>
Classes: 7 packages by
Country: Brazil Brazil
Age: 39
All time rank: 2095136 in Brazil Brazil
Week rank: 258 Up21 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x


use alesinicio\AsyncExecutor\AsyncExecutor;


$async = new AsyncExecutor('/usr/bin/php');

$pid = $async->runProcess(__DIR__.'/bg_process.php', ['param01', 'param02']);



Async Processor

This a simple class that can help spawning CLI processes, either as "run-and-forget" or "run-and-keep-running" modes.



Useful when you want to spawn a CLI process and make it run in the background. You will NOT get any return from the process itself.

Basic usage:

$async = new AsyncExecutor('/usr/bin/php');
$async->runProcess('path_to_script', ['param01', 'param02']);


Useful when you want to spawn CLI processes and keep them running no matter what.

The class monitors the PID of the processes to check if they are still running, and restarts automatically if needed.

Basic usage:

$async = new AsyncExecutor('/usr/bin/php');
$multiAsync = new AsyncMultiProcess($async);
$multiAsync->addProcess(new AsyncProcess('instance_01', 'path_to_script_01', ['param01']));
$multiAsync->addProcess(new AsyncProcess('instance_02', 'path_to_script_02', ['param02', 'param03']));

If a process fails to execute due to a non-existing script, you can set the time the class will wait to retry the execution (default, 5 seconds).

You can also configure the AsyncMultiProcess to abort execution if non-existing script is detected, effectively canceling everything (running processes will not be closed, though).

  Files folder image Files  
File Role Description
Files folder imageexamples (3 files)
Files folder imagesrc (4 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file bg_process.php Aux. Auxiliary script
  Accessible without login Plain text file run_and_forget.php Example Example script
  Accessible without login Plain text file run_and_keep_running.php Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file AsyncExecutor.php Class Class source
  Plain text file AsyncMultiProcess.php Class Class source
  Plain text file AsyncProcess.php Class Class source
  Plain text file FileNotFoundException.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,128
This week:104Up