-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline_1_step2.php
47 lines (38 loc) · 1004 Bytes
/
pipeline_1_step2.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
<?php
use aventri\Multiprocessing\Example\Steps\Pipeline1\Step2;
use aventri\Multiprocessing\Example\Steps\Pipeline1\StepInterface;
use aventri\Multiprocessing\Task\Task;
include realpath(__DIR__ . "/../../vendor/") . "/autoload.php";
(new class extends Task
{
/**
* @var int
*/
private $pid;
public function __construct()
{
$this->pid = getmypid();
}
private function wasteTime($value)
{
$result = 1;
for($i = 1; $i < 10000000; $i++) {
$result += $i;
}
return $value * $value;
}
/**
* @param StepInterface $step
* @return mixed|void
*/
public function consume($step)
{
$step2 = new Step2($step);
$step2->pid = $this->pid;
$startTime = microtime(true);
$step2->value = $this->wasteTime($step->value);
$totalTime = microtime(true) - $startTime;
$step2->totalTime = $totalTime;
$this->write($step2);
}
})->listen();