/** * Runs calculating actors */ public function start() { $initialAddress = 22343; for ($i = 0; $i < $this->numberOfProcesses; ++$i) { $address = $initialAddress + $i; $iterations = rand(100, 200); // according to task should be set by random $this->addresses[] = $address; $this->processes[] = Actor::createAndRun($address, $this->getCalculatorHandler($iterations, $this->addressToReport)); Actor::sendMessage($address, 'start'); } }
<?php require __DIR__ . '/vendor/autoload.php'; $startTime = time(); $config = (require __DIR__ . '/config.php'); \Phactor\Phactor\App::launch($config['appAddress'], function ($message, $state) use($startTime) { if ($message === '') { \Phactor\Phactor\Actor::createAndRun($state['aggregatorAddress'], function ($message, $state) use($startTime) { if (!isset($state['aggregator'])) { $state['aggregator'] = new \Phactor\App\WebAggregator(__DIR__ . '/index.html', $startTime); } $state['aggregator']->addReport(unserialize($message)); $state['aggregator']->dump(); return $state; }); $service = new \Phactor\App\CalculatorMultiProcessService($state['numberOfProcesses'], $state['aggregatorAddress']); $service->start(); while (true) { sleep(rand(1, 100)); echo 'Asking for report...' . PHP_EOL; foreach ($service->getAddresses() as $calculatorAddress) { \Phactor\Phactor\Actor::sendMessage($calculatorAddress, 'report'); } } } return $state; }, $config);