Exemplo n.º 1
0
 /**
  * waits and connects the process of map container
  *
  * @param   Snidel_MapContainer
  * @return  void
  * @throws  RuntimeException
  */
 private function waitsAndConnectsProcess(Snidel_MapContainer $mapContainer)
 {
     if ($this->joined) {
         return;
     }
     while ($mapContainer->isProcessing()) {
         $status = null;
         $childPid = pcntl_waitpid(-1, $status);
         if (!pcntl_wifexited($status)) {
             $message = 'error in child.';
             $this->error($message);
             throw new RuntimeException($message);
         }
         $data = new Snidel_Data($childPid);
         try {
             $this->results[$childPid] = $data->readAndDelete();
         } catch (RuntimeException $e) {
             throw $e;
         }
         unset($this->childPids[array_search($childPid, $this->childPids)]);
         if ($nextMap = $mapContainer->nextMap($childPid)) {
             try {
                 $nextMapPid = $this->fork($nextMap->getCallable(), array($this->results[$childPid]), null, $nextMap->getToken());
             } catch (RuntimeException $e) {
                 throw $e;
             }
             $this->info('started next map ' . $childPid . ' -> ' . $nextMapPid);
             $nextMap->countTheForked();
             $nextMap->addChildPid($nextMapPid);
         }
         $mapContainer->countTheCompleted($childPid);
     }
     $this->joined = true;
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function writeAndRead()
 {
     $data = new Snidel_Data(getmypid());
     $data->write('foo');
     $this->assertSame($data->readAndDelete(), 'foo');
 }