From ec47c2bca0fb084cbd10abd6558769bba818d000 Mon Sep 17 00:00:00 2001 From: Paminger Date: Thu, 7 May 2015 08:25:06 +0200 Subject: [PATCH] Prozessklasse --- include/process.class.php | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 include/process.class.php diff --git a/include/process.class.php b/include/process.class.php new file mode 100644 index 000000000..b8540d091 --- /dev/null +++ b/include/process.class.php @@ -0,0 +1,87 @@ + + */ + +class process +{ + private $pid; + private $command; + + public $lastout; + public $output; + public $exit; + + public function __construct($cl=false) + { + if ($cl != false) + { + $this->command = $cl; + $this->runCom(); + } + } + private function runCom() + { + $command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!'; + $this->lastout=exec($command, $this->output, $this->exit); //exec($command ,$op); + $this->pid = (int)$this->output[0]; + } + + public function setPid($pid) + { + $this->pid = $pid; + } + + public function getPid() + { + return $this->pid; + } + + public function status() + { + $command = 'ps -p '.$this->pid; + exec($command,$op); + if (!isset($op[1])) + return false; + else + return true; + } + + public function start() + { + if ($this->command != '') + $this->runCom(); + else + return true; + } + + public function stop() + { + $command = 'kill '.$this->pid; + exec($command); + if ($this->status() == false) + return true; + else + return false; + } +} +?>