项目作者: symfony-bundles

项目描述 :
Fork Library
高级语言: PHP
项目地址: git://github.com/symfony-bundles/fork.git
创建时间: 2016-06-07T12:09:00Z
项目社区:https://github.com/symfony-bundles/fork

开源协议:MIT License

下载


SymfonyBundles Fork Library

SensioLabsInsight

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

Installation

Install the library with composer:

  1. composer require symfony-bundles/fork

How to use (only cli-mode)

Create the fork service:

  1. use SymfonyBundles\Fork;
  2. $fork = new Fork\Fork();

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

  1. namespace AppBundle\Task;
  2. use SymfonyBundles\Fork\TaskInterface;
  3. class DemoTask implements TaskInterface
  4. {
  5. public function execute()
  6. {
  7. echo "Hello World!\n";
  8. }
  9. }

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

  1. use AppBundle\Task\DemoTask;
  2. $task = new DemoTask();
  3. $fork->attach($task)->run(4)->wait(); // 4 - this is number of subprocesses

And another example:

  1. $task1 = new DemoTask();
  2. $task2 = new DemoTask();
  3. $task3 = new DemoTask();
  4. $fork->attach($task1)->attach($task2)->attach($task3);
  5. $fork->run(); // by default, the optimal number of subprocesses will be determined
  6. $fork->wait();

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