#关闭服务
public function closed(){
if(strpos(PHP_OS,"Linux")!==false){
#Linux套字
$exec_power ="kill -s 9 `ps -aux | grep queue| grep -v grep | awk '{print $2}'`";
//$exec_power ='cd '. ROOT_PATH .'; php think queue:restart';
}else if(strpos(PHP_OS,"WIN")!==false){
#Win套字
$exec_power ='cd /d '. ROOT_PATH .' & php think queue:restart ';
}else{
$this->error('未识别的操作系统');
}
#命令执行
$message ='';
try {
$message = shell_exec($exec_power);
} catch (\Exception $e) {
$message = $e->getMessage();
}
$this->success('关闭服务成功','',$exec_power);
}
#启动服务
public function powers(){
$id =$this->request->param('id');
$info=$this->model->where(array('id'=>$id))->find();
$daemon =1;
#获取标识
$job_code =$info['job_code'];
if(!empty($job_code)){
#判断win还是linux
if(strpos(PHP_OS,"Linux")!==false){
#Linux套字
if($daemon){
//$exec_power ='cd '. ROOT_PATH .'; php think queue:work --queue ' .$job_code.' --daemon';
//后台挂起 不同等待
$exec_power ='cd '. ROOT_PATH .'; php think queue:work --queue ' .$job_code.' --daemon > /dev/null 2> /dev/null &';
}else{
$exec_power ='cd '. ROOT_PATH .'; php think queue:work --queue ' .$job_code;
}
}else if(strpos(PHP_OS,"WIN")!==false){
#Win套字
if($daemon){
//$exec_power ='cd /d '. ROOT_PATH .' & php think queue:work --queue ' .$job_code.' --daemon';
$exec_power ='cd /d '. ROOT_PATH .' & start /B php think queue:work --queue ' .$job_code.' --daemon';
}else{
$exec_power ='cd /d "'. ROOT_PATH .'" & php think queue:work --queue ' .$job_code;
}
}else{
$this->error('未识别的操作系统');
}
#命令执行
$message ='';
if($daemon>0){
$message =pclose(popen($exec_power, 'r'));
//$message =shell_exec($exec_power);
}else{
try {
$message = shell_exec($exec_power);
} catch (\Exception $e) {
$message = $e->getMessage();
}
}
$this->success('启动成功','',$exec_power);
}else{
$this->error('未找到对应的任务标识');
}
}