我使用PHP来启动FFMPEG转码命令。这是一个在Ubuntu 10.04 Server上运行的典型LAMP设置,没有什么特别的配置。PHP执行返回不正确的进程ID
我遇到的问题是当我运行PHP Exec命令时,它返回不正确的进程ID。而不是返回适当的PID,而是返回2以上的一个。即FFMPEG进程ID将是3557,但是PHP Exec返回3559.
我一直设法每次生成这个。问题是,我真的需要正确的进程ID,所以如果我选择,我可以稍后停止进程。
ffmpeg的命令的工作,并开始不会有问题,所以我不认为这是问题的根源:
$cmd = "ffmpeg -r 4 -f mjpeg -an -i 'http://" . $internalhost . ":" . $stream_port . "'
-vcodec libx264 -vpre fastfirstpass -vpre baseline -b 24k -bt 32k -threads 0
http://localhost:8090/" . $localport . ".ffm";
$ffmpg = new Process($cmd);
我知道...这是很丑陋,但它的工作原理和我不我认为变量很重要。
要启动我使用从PHP手册网站,该网站是如下一类代码:
class Process
{
private $pid;
private $command;
public function __construct($cl=false){
if ($cl != false){
$this->command = $cl;
$this->runCom();
}
}
private function runCom(){
$command = 'nohup '.$this->command.' > /dev/null 2> /dev/null & echo $!';
exec($command ,$op);
$this->pid = (int)$op[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;
}
}
我猜的情况是,由于某种原因FFMPEG被踢了另外2个工艺和替代返回主进程的PID,它返回最后一个进程的PID。
虽然可能是错误的,但我仍然挠挠我的脑袋。
编辑使用内联代码标记http://stackoverflow.com/editing-help#code – 2013-02-03 20:29:13