php运行java命令_PHP后台运行命令并管理运行程序

php后台运行命令并管理后台运行程序

class ProcessModel{

private $pid;

private $command;

private $resultToFile = '';

public function __construct($cl=false){

if ($cl != false){

$this->command = $cl;

}

}

public function runCom($cl=false){

if($cl) {

$this->resultToFile = md5($cl);

$this->command = $cl;

$command = 'nohup '.$cl.' 1>/tmp/'.$this->resultToFile.'_http_proess.txt & echo $! 2>&1';

exec($command ,$op);

$this->pid = (int)$op[0];

return $this->pid;

}else{

return 0;

}

}

public function setPid($pid){

$this->pid = $pid;

}

public function getPid(){

return $this->pid;

}

public function getContent() {

$command = 'cat /tmp/'.md5($this->command).'_http_proess.txt';

exec($command ,$op);

if(is_array($op)) {

$op = implode("\n", $op);

}

return $op;

}

public function isRuning(){

$command = 'ps -p '.$this->pid;

exec($command,$op);

if (!isset($op[1])) {

return false;

}else{

return true;

}

}

public function stop(){

$command = 'kill '.$this->pid;

exec($command);

if ($this->status() == false){

return true;

}else{

return false;

}

}

}

转载至链接:https://my.oschina.net/colin86/blog/1859777

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值