public function launch($action='listen')
    {
        // Env check
        if (!$this->_isLinux()) {
            die("Error environment: Queue Launcher requires Linux OS, you could use `work` or `single` instead.");
        }
        
        // Action check
        if (!in_array($action, ['listen', 'work'])) {
            die("Action: `{$action}` is invalid for Launcher.");
        }
        
        // Null so far
        $logPath = '/dev/null';
        
        // Action command builder
        $route = $this->router->fetch_directory() . $this->router->fetch_class() . "/{$action}";
        $cmd = "{$this->phpCommand} " . FCPATH . "index.php {$route}";

        // Check process exists
        $search = str_replace('/', '\/', $route);
        // $result = shell_exec("pgrep -f \"{$search}\""); // Lacks of display info
        // Find out the process by name
        $psCmd = "ps aux | grep \"{$search}\" | grep -v grep";
        $psInfoCmd = "ps aux | egrep \"PID|{$search}\" | grep -v grep";
        $exist = (shell_exec($psCmd)) ? true : false;

        if ($exist) {
            
            $psInfo = shell_exec($psInfoCmd);
            die("Skip: Same process `{$action}` is running: {$route}.\n------\n{$psInfo}");
        }

        // Launch by calling command
        $launchCmd = "{$cmd} > {$logPath} &";
        $result = shell_exec($launchCmd);
        $result = shell_exec($psCmd);
        $psInfo = shell_exec($psInfoCmd);
        echo "Success to launch process `{$action}`: {$route}.\nCalled command: {$launchCmd}\n------\n{$psInfo}";

        return;
    }
public function launch($action='listen')
    {
        // Env check
        if (!$this->_isLinux()) {
            die("Error environment: Queue Launcher requires Linux OS, you could use `work` or `single` instead.");
        }
        
        // Action check
        if (!in_array($action, ['listen', 'work'])) {
            die("Action: `{$action}` is invalid for Launcher.");
        }
        
        // Null so far
        $logPath = '/dev/null';
        
        // Action command builder
        $route = $this->router->fetch_directory() . $this->router->fetch_class() . "/{$action}";
        $cmd = "{$this->phpCommand} " . FCPATH . "index.php {$route}";

        // Check process exists
        $search = str_replace('/', '\/', $route);
        // $result = shell_exec("pgrep -f \"{$search}\""); // Lacks of display info
        // Find out the process by name
        $psCmd = "ps aux | grep \"{$search}\" | grep -v grep";
        $psInfoCmd = "ps aux | egrep \"PID|{$search}\" | grep -v grep";
        $exist = (shell_exec($psCmd)) ? true : false;

        if ($exist) {
            
            $psInfo = shell_exec($psInfoCmd);
            die("Skip: Same process `{$action}` is running: {$route}.\n------\n{$psInfo}");
        }

        // Launch by calling command
        $launchCmd = "{$cmd} > {$logPath} &";
        $result = shell_exec($launchCmd);
        $result = shell_exec($psCmd);
        $psInfo = shell_exec($psInfoCmd);
        echo "Success to launch process `{$action}`: {$route}.\nCalled command: {$launchCmd}\n------\n{$psInfo}";

        return;
    }
public function launch ( $ action = 'listen' ) { // Env check if ( ! $ this -> _isLinux ( ) ) { die ( "Error environment: Queue Launcher requires Linux OS, you could use `work` or `single` instead." ) ; } // Action check if ( ! in_array ( $ action , [ 'listen' , 'work' ] ) ) { die ( "Action: `{$action}` is invalid for Launcher." ) ; } // Null so far $ logPath = '/dev/null' ; // Action command builder $ route = $ this -> router -> fetch_directory ( ) . $ this -> router -> fetch_class ( ) . "/{$action}" ; $ cmd = "{$this->phpCommand} " . FCPATH . "index.php {$route}" ; // Check process exists $ search = str_replace ( '/' , '\/' , $ route ) ; // $result = shell_exec("pgrep -f \"{$search}\""); // Lacks of display info // Find out the process by name $ psCmd = "ps aux | grep \"{$search}\" | grep -v grep" ; $ psInfoCmd = "ps aux | egrep \"PID|{$search}\" | grep -v grep" ; $ exist = ( shell_exec ( $ psCmd ) ) ? true : false ; if ( $ exist ) { $ psInfo = shell_exec ( $ psInfoCmd ) ; die ( "Skip: Same process `{$action}` is running: {$route}.\n------\n{$psInfo}" ) ; } // Launch by calling command $ launchCmd = "{$cmd} > {$logPath} &" ; $ result = shell_exec ( $ launchCmd ) ; $ result = shell_exec ( $ psCmd ) ; $ psInfo = shell_exec ( $ psInfoCmd ) ; echo "Success to launch process `{$action}`: {$route}.\nCalled command: {$launchCmd}\n------\n{$psInfo}" ; return ; }
Launcher for guaranteeing unique process

This launcher would launch specified process if there are no any other same process running
by launcher. Using this for launching `listen` could ensure there are always one listener
running at the same time with repeated launch calling likes crontab, which could also ensure
listener process would never gone away.

@param string $action
@return void
Launcher for guaranteeing unique process