/**
  * @param array $parameters
  * @return void|\zaboy\async\Promise\Interfaces\PromiseInterface
  * @throws CallbackException
  */
 public function asyncCall(array $parameters = [])
 {
     if (is_null($this->script)) {
         if (!is_file(self::SCRIPT_NAME)) {
             throw new CallbackException('The handler script "scriptProxy.php" does not exist in the folder "script"');
         }
         $this->script = self::SCRIPT_NAME;
     }
     $promise = $this->promiseBroker->make();
     // Merge the options from config with passed options
     /** @var array|null $parameters */
     $options = array_merge(['promise' => $promise->getId()], $parameters);
     // Files names for stdout and stderr
     $stdOutFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('stdout_', 1);
     $stdErrFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('stderr_', 1);
     /** @var  CommandLineWorker $commandLineWorker */
     $commandLineWorker = new CommandLineWorker();
     $cmd = $this->commandPrefix . ' ' . $this->script;
     $cmd .= $commandLineWorker->makeParamsString(['scriptOptions' => $commandLineWorker->encodeParams($options)]);
     $cmd .= "  1>{$stdOutFilename} 2>{$stdErrFilename} & echo \$!";
     $output = trim(shell_exec($cmd));
     //        if (!is_numeric($output)) {
     //            throw new CallbackException("The output of the script is ambiguous."
     //                . "Probably there is an error in the script");
     //        }
     //        $pId = intval($output);
     //
     //        $this->scriptBroker->setFileInfo($promise->getId(), $pId, $stdOutFilename, $stdErrFilename);
     return $promise;
 }
示例#2
0
 public function test__delete()
 {
     $promise = $this->object->make();
     $id = $promise->getId();
     $result = $this->object->delete($id);
     $this->assertTrue($result);
     $this->setExpectedException('\\zaboy\\async\\Promise\\PromiseException');
     $promise = $this->object->get($id)->getState();
     $this->assertFalse($this->object->delete($id));
 }
示例#3
0
 /**
  * Reads a content of log-files of specified process
  *
  * @param $row
  * @throws \Exception
  */
 public function postFinishProcess($row)
 {
     $errors = $this->parser->parseFile($row['stderr']);
     $output = $this->parser->parseFile($row['stdout']);
     $promise = $this->promiseBroker->get($row['promiseId']);
     if ($errors['fatalStatus']) {
         $promise->reject($errors['message']);
     } else {
         $promise->resolve($output['message'] . PHP_EOL . $errors['message']);
     }
 }