Exemple #1
0
 public function testKill()
 {
     $cmd = new Command('php', __DIR__ . '/command/basic.php');
     if (\Ark4ne\Processes\System\OS\Manager::isWin()) {
         $this->assertNull($cmd->exec(true));
     } else {
         $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $cmd->exec(true));
     }
     $processes = System::processes('php');
     $this->assertEquals(2, count($processes));
     $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $processes[0]);
     $processes[1]->kill();
     $processes = System::processes('php');
     $this->assertEquals(1, count($processes));
 }
Exemple #2
0
 /**
  * @return string
  * @throws \Ark4ne\Processes\Exception\OSUnknownException
  */
 private function optsToString()
 {
     $options = '';
     if (count($this->options)) {
         $opts = [];
         foreach ($this->options as $key => $opt) {
             if (is_null($opt)) {
                 $opts[] = $key;
             } else {
                 $opts[] = $key . '="' . Manager::os()->escapeQuoteCli(Str::fromVar($opt)) . '"';
             }
         }
         $options = trim(Arr::toString($opts, ' --', '--'));
     }
     return $options;
 }
Exemple #3
0
 /**
  * Return an Array of processes list in execution.
  *
  * @param null $id
  *
  * @return Process[]
  * @throws \Ark4ne\Processes\Exception\OSUnknownException
  */
 public static function processById($id)
 {
     return Manager::os()->processById($id);
 }
Exemple #4
0
 public function testExecBackground()
 {
     if (\Ark4ne\Processes\System\OS\Manager::isLinux()) {
         $command = new Command('php', __DIR__ . '/command/basic.php');
         $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $command->exec(true));
     }
     if (\Ark4ne\Processes\System\OS\Manager::isWin()) {
         $command = new Command('php', __DIR__ . '\\command\\basic.php');
         $this->assertNull($command->exec(true));
     }
 }
Exemple #5
0
 public function testProcessBackground()
 {
     $cmd = new Command('php', __DIR__ . '/command/basic.php');
     $this->assertEquals('php ' . __DIR__ . '/command/basic.php', $cmd->getCommandLine());
     $cmd->exec(true);
     $processes = System::processes('php');
     $this->assertEquals(count($processes), Manager::os()->countProcesses('php'));
     $this->assertTrue(is_array($processes));
     $this->assertEquals(2, count($processes));
     $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $processes[0]);
     $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $processes[1]);
     $processes[1]->kill();
 }