-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi_worker_pool_stream.php
52 lines (46 loc) · 1.67 KB
/
multi_worker_pool_stream.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
<?php
use aventri\Multiprocessing\Example\Steps\Pipeline1\StepInterface;
use aventri\Multiprocessing\PipelineFactory;
use aventri\Multiprocessing\PoolFactory;
use aventri\Multiprocessing\Queues\WorkQueue;
include realpath(__DIR__ . "/../vendor/") . "/autoload.php";
$step1 = "php " . realpath(__DIR__) . "/proc_scripts/pipeline_1_step1.php";
$step2 = "php " . realpath(__DIR__) . "/proc_scripts/pipeline_1_step2.php";
$step3 = "php " . realpath(__DIR__) . "/proc_scripts/pipeline_1_step3.php";
$collected = PipelineFactory::create([
PoolFactory::create([
"task" => $step1,
"queue" => new WorkQueue(range(1, 30)),
"num_processes" => 8,
"done" => function (StepInterface $step) {
echo "Pool 1: " . $step->getResult() . PHP_EOL;
},
"error" => function (ErrorException $e) {
echo $e->getTraceAsString().PHP_EOL;
}
]),
PoolFactory::create([
"task" => $step2,
"queue" => new WorkQueue(),
"num_processes" => 8,
"done" => function (StepInterface $step) {
echo "Pool 2: " . $step->getResult() . PHP_EOL;
},
"error" => function (Exception $e) {
echo $e->getTraceAsString().PHP_EOL;
}
]),
PoolFactory::create([
"task" => $step3,
"queue" => new WorkQueue(),
"num_processes" => 8,
"done" => function (StepInterface $step) {
echo "Pool 3: " . $step->getResult() . PHP_EOL;
echo "Whole Process took: " . $step->getTime() . PHP_EOL;
},
"error" => function (Exception $e) {
echo $e->getTraceAsString().PHP_EOL;
}
])
])->start();
print_r($collected);