【发布时间】:2016-08-10 05:29:59
【问题描述】:
经过多次尝试,我们未能获得 pid 号。
代码:
<?php
$server = "optimus.xxx.xx";
//ip address will work too i.e. 192.168.254.254 just make sure this is your public ip address not private as is the example
//specify your username
$username = "root";
//select port to use for SSH
$port = "22";
//command that will be run on server B
$command = "./sp-sc-auth sop://broker.sopcast.com:3912/149255 3908 8908 > /dev/null &";
//$command = "./sop.sh sop://broker.sopcast.com:3912/149255 1234 > /dev/null & echo $!";
//$command = "./sop.sh sop://broker.sopcast.com:3912/149255 1234 & echo $!"; // scoate si restu de info
//$command = "ps - ef | grep -v grep | grep ./sop.sh sop://broker.sopcast.com:3912/149255 1234 | awk '{print $2}'";
//form full command with ssh and command, you will need to use links above for auto authentication help
$cmd_string = "ssh -p ".$port." ".$username."@".$server." ".$command;
//this will run the above command on server A (localhost of the php file)
exec($cmd_string, $output);
//return the output to the browser
//This will output the uptime for server B on page on server A
echo '<pre>';
print_r($output);
echo '</pre>';
?>
如果从这里交换:
$command = "./sp-sc-auth sop://broker.sopcast.com:3912/149255 3908 8908 > /dev/null & echo $!";
是显示另一个数字而不是实数pid。
如果从 bash 中输入它可以正常工作并显示 pid。 我不明白哪里错了。
从 php 显示这个 pid:
Array
( [0] => 9397 )
真正的pid是7452
编辑: 桌面访问 Web 服务器(服务器 1)和服务器 1 在服务器 2 的 sopcast 播放器内启动。服务器 2 向服务器 1 发送 pid 以在 web 服务器 json 中显示。
编辑 2:
pid number 是他从 web 服务器输出的 ppid 数,而不是运行通过 ssh 发送的命令的服务器 2。
【问题讨论】:
-
你是否正确地转义了 $ 以便 PHP 不认为它是一个变量?
echo \$! -
“真实”进程ID和“非真实”进程ID有什么区别?这里的“真实”真的是什么意思?请记住,ssh 连接肯定会创建另一个 shell 环境,因此会创建另一个进程。与 php 的
exec命令相同。 -
Brandon 添加此 \ 不更改 id pid 不起作用
-
@arkascha if not put this " > /dev/null" 显示无限文本
-
抱歉,我不明白你最后的评论是什么意思...