public function testStart_Start2ProcessWithOnePidFile() { $pidfile = $this->_pidFile; $process = \Comos\Qpm\Process\Process::fork(function () use($pidfile) { $man = new Manager($pidfile); $man->start(); usleep(200 * 1000); }); usleep(100 * 1000); $man1 = new Manager($pidfile); $process1 = $man1->getProcess(); $this->assertTrue($process1 instanceof \Comos\Qpm\Process\Process); try { $man2 = new Manager($this->_pidFile); $man2->start(); $this->fail('expects Exception'); } catch (\Exception $e) { $st = 0; $pidfile = pcntl_wait($st); $this->assertEquals($pidfile, $process->getPid()); $this->assertEquals($pidfile, $process1->getPid()); $this->assertTrue(\pcntl_wifexited($st)); $this->assertTrue($e instanceof \Comos\Qpm\Pid\Exception); $this->assertEquals('process exists, no need to start a new one', $e->getMessage()); } }
<?php /** * @author bigbigant */ require __DIR__ . '/bootstrap.inc.php'; use Comos\Qpm\Pid\Manager; $man = new Manager(__DIR__ . '/pid_main.php.pid'); echo $man->getProcess()->getPid() . "\n";
<?php /** * @author bigbigant */ require __DIR__ . '/bootstrap.inc.php'; use Comos\Qpm\Pid\Manager; echo "Process is running. Ctrl+c to quit.\nYou can execute `php pid_check.php` to check the PID of current process.\n"; $man = new Manager(__FILE__ . '.pid'); $man->start(); while (true) { sleep(10); }