This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.php
57 lines (48 loc) · 2.08 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* DocBlox
*
* PHP Version 5
*
* @category DocBlox
* @package Parallel
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://docblox-project.org
*/
/** Include the manager as we do not autoload */
require_once 'Manager.php';
/** Include the worker as we do not autoload */
require_once 'Worker.php';
/** Include the worker's pipe as we do not autoload */
require_once 'WorkerPipe.php';
// -----------------------------------------------------------------------------
// method 1: using a fluent interface and the addWorker helper.
// -----------------------------------------------------------------------------
$mgr = new DocBlox_Parallel_Manager();
$mgr
->addWorker(new DocBlox_Parallel_Worker(function() { sleep(1); return 'a'; }))
->addWorker(new DocBlox_Parallel_Worker(function() { sleep(1); return 'b'; }))
->addWorker(new DocBlox_Parallel_Worker(function() { sleep(1); return 'c'; }))
->addWorker(new DocBlox_Parallel_Worker(function() { sleep(1); return 'd'; }))
->addWorker(new DocBlox_Parallel_Worker(function() { sleep(1); return 'e'; }))
->execute();
/** @var DocBlox_Parallel_Worker $worker */
foreach ($mgr as $worker) {
var_dump($worker->getResult());
}
// -----------------------------------------------------------------------------
// method 2: using the manager as worker array
// -----------------------------------------------------------------------------
$mgr = new DocBlox_Parallel_Manager();
$mgr[] = new DocBlox_Parallel_Worker(function() { sleep(1); return 'f'; });
$mgr[] = new DocBlox_Parallel_Worker(function() { sleep(1); return 'g'; });
$mgr[] = new DocBlox_Parallel_Worker(function() { sleep(1); return 'h'; });
$mgr[] = new DocBlox_Parallel_Worker(function() { sleep(1); return 'i'; });
$mgr[] = new DocBlox_Parallel_Worker(function() { sleep(1); return 'j'; });
$mgr->execute();
/** @var DocBlox_Parallel_Worker $worker */
foreach ($mgr as $worker) {
var_dump($worker->getResult());
}