Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 2.68 KB

README.md

File metadata and controls

85 lines (64 loc) · 2.68 KB

SymfonyBundles Fork Library

SensioLabsInsight

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Stable Version License

Installation

Install the library with composer:

composer require symfony-bundles/fork

How to use (only cli-mode)

Create the fork service:

use SymfonyBundles\Fork;

$fork = new Fork\Fork();

Create a task that implements an interface SymfonyBundles\Fork\TaskInterface. For example:

namespace AppBundle\Task;

use SymfonyBundles\Fork\TaskInterface;

class DemoTask implements TaskInterface
{
    public function execute()
    {
        echo "Hello World!\n";
    }
}

Now that the task is created, you can execute her in a plurality processes:

use AppBundle\Task\DemoTask;

$task = new DemoTask();

$fork->attach($task)->run(4)->wait(); // 4 - this is number of subprocesses

And another example:

$task1 = new DemoTask();
$task2 = new DemoTask();
$task3 = new DemoTask();

$fork->attach($task1)->attach($task2)->attach($task3);
$fork->run(); // by default, the optimal number of subprocesses will be determined
$fork->wait();

If you call method wait, the current process (main) will wait while all child processes will be finished.