PHP Queue Jobs Piping: Send jobs to a pipeline to be executed later

Recommend this page to a friend!
  Info   View files Example   View files View files (21)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-11-28 (18 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 33 This week: 1All time: 10,038 This week: 208Up
Version License PHP version Categories
php_component_proces 1.0GNU Lesser Genera...5PHP 5, Language
Description Author

This package can send jobs to a pipeline to be executed later.

It creates a queue of jobs to be executed later by storing objects implement those jobs.

The package can also process the queued jobs by calling the job objects stored in the pipeline queue.

Innovation Award
PHP Programming Innovation award nominee
November 2020
Nominee
Vote
Sometimes PHP scripts need to execute several tasks that are defined dynamically only when a given script is run.

For instance, this can be the case of a newsletter mailing list processing task that can be split in smaller tasks like 1) pull the list of recipients from a database, 2) merge the recipient information in the newsletter message contents, 3) send the newsletter messages to each recipient.

This package allows implementing a queue of tasks to be run by the same script.

Applications just need to define objects of classes that will run the different tasks and pass them to this package, so the task objects are queued.

Later, this package can run all the tasks one after the other by calling the objects that were queued.

This way this package can simplify the division of complex tasks in smaller tasks that execute simpler steps.

Manuel Lemos
Picture of nvb
  Performance   Level  
Name: nvb <contact>
Classes: 16 packages by
Country: Germany Germany
Innovation award
Innovation award
Nominee: 8x

 

Details

Process Pipe Component in PHP

This free as in freedom component ease up creation of a pipe) for processes in php.

Indeed, it is a pseudo pipeline#Pseudo-pipelines) (process collection or process batch) since the php process is single threaded so far.

Currently, there is no plan to bloat the code base with an implementation of STDIN, STDOUT or STDERR. Errors can be handled by the thrown exception. Input is defined by the ExecutableInterface, as well as the output (return value).

The build status of the current master branch is tracked by Travis CI: Build Status Latest stable

The scrutinizer status are: code quality

The versioneye status is: dependencies

Downloads: Downloads this Month

It is also available at openhub.net.

Why?

  • separate complex operations into simpler
  • easy up unit testing for smaller processes
  • separate responsibility (data generator/transformer/validator/flow manipulator)
  • create process chains you can read in the code (separate integration code from operation code)
  • no dependencies (except you want to join the development team)

Examples

Install

By Hand

mkdir -p vendor/net_bazzline/php_component_process_pipe
cd vendor/net_bazzline/php_component_process_pipe
git clone https://github.com/bazzline/php_component_process_pipe

With Packagist

composer require net_bazzline/php_component_process_pipe:dev-master

Usage

By using the pipe method for multiple process

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe();
    
    $pipe->pipe(
        new ProcessOne(), 
        new ProcessTwo()
    );
    
    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

By using the pipe method once for each process

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe();
    
    $pipe->pipe(new ProcessOne());
    $pipe->pipe(new ProcessTwo());
    
    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

By instantiation

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe(
        new ProcessOne(),
        new ProcessTwo()
    );
    
    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

By doing all

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe(
        new ProcessOne(),
        new ProcessTwo()
    );
    
    $pipe->pipe(new ProcessThree());
    $pipe->pipe(
        new ProcessFour(),
        new ProcessFive()
    );

    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

API

API is available at bazzline.net.

History

  • upcomming * @todo * add support for lambdafunctions or move to __invoke() fully * added example for tee) * fixed invalid package names
  • 1.1.1 - released at 29.07.2016 * fixed invalid example links * removed local api * updated dependency
  • 1.1.0 - released at 06.03.2016 * added php 7.0 to travis ci * fixed invalid version link * moved to psr-4 autoloading * updated dependency
  • 1.0.5 - released at 11.12.2015 * updated dependency
  • 1.0.4 - released at 18.11.2015 * updated dependency
  • 1.0.3 - released at 28.08.2015 * updated dependency
  • 1.0.2 - released at 04.07.2015 * removed depenendy to phpmd * updated dependency
  • 1.0.1 - released at 08.02.2015 * add "StopExecutionException" * removed dependency to apigen
  • 1.0.0 - released at 12.11.2014 * initial release

Links

thanks to

other pipe implementations

Final Words

Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it. Donate something if you love it :-].

  Files folder image Files  
File Role Description
Files folder imageexample (7 directories)
Files folder imagesource (5 files)
Files folder imagetest (3 files)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
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 phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
Files folder imageDataFlowManipulator (1 file)
Files folder imageFailingExecution (1 file)
Files folder imageInputArray (1 file)
Files folder imageInputGenerator (1 file)
Files folder imageInputTransformer (1 file)
Files folder imageInputValidator (1 file)
Files folder imageNoInput (1 file)

  Files folder image Files  /  example  /  DataFlowManipulator  
File Role Description
  Accessible without login Plain text file run.php Example There are many template engines that are often used to render the output of pages generated by PHP applications. Different developers prefer to use different template engines. This package makes it possible for applications implemented using the the Dframe framework view rendering support using several template engines of the choice of the application developer.

  Files folder image Files  /  example  /  FailingExecution  
File Role Description
  Accessible without login Plain text file run.php Example Example

  Files folder image Files  /  example  /  InputArray  
File Role Description
  Accessible without login Plain text file run.php Example Example

  Files folder image Files  /  example  /  InputGenerator  
File Role Description
  Accessible without login Plain text file run.php Example Example

  Files folder image Files  /  example  /  InputTransformer  
File Role Description
  Accessible without login Plain text file run.php Example Example

  Files folder image Files  /  example  /  InputValidator  
File Role Description
  Accessible without login Plain text file run.php Example Example

  Files folder image Files  /  example  /  NoInput  
File Role Description
  Accessible without login Plain text file run.php Example Example

  Files folder image Files  /  source  
File Role Description
  Plain text file ExecutableException.php Class Class source
  Plain text file ExecutableInterface.php Class Class source
  Plain text file InvalidArgumentException.php Class Class source
  Plain text file Pipe.php Class Class source
  Plain text file PipeInterface.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file PipeTest.php Class Class source
  Plain text file TestCase.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:33
This week:1
All time:10,038
This week:208Up

For more information send a message to info at phpclasses dot org.