コード例 #1
0
ファイル: ProcessTest.php プロジェクト: ark4ne/php-processes
 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));
 }
コード例 #2
0
ファイル: Command.php プロジェクト: ark4ne/php-processes
 /**
  * @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;
 }
コード例 #3
0
ファイル: System.php プロジェクト: ark4ne/php-processes
 /**
  * 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);
 }
コード例 #4
0
ファイル: CommandTest.php プロジェクト: ark4ne/php-processes
 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));
     }
 }
コード例 #5
0
ファイル: OSTest.php プロジェクト: ark4ne/php-processes
 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();
 }