After many attempts we failed to do was get the pid number.
code:
<?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>';
?>
if exchange from this :
$command = "./sp-sc-auth sop://broker.sopcast.com:3912/149255 3908 8908 > /dev/null & echo $!";
is show another number not real number pid.
and if put this from bash is work fine and show the pid. I do not understand where wrong.
from php is show this pid:
Array
( [0] => 9397 )
and real pid is 7452
Edit: Desktop acces web server (server 1) and server 1 start inside server 2 sopcast player. and server 2 is send pid a server 1 for show in web server json.
Edit 2:
pid number which is the number of ppid him out from the web server, not the server 2 where it runs command sent via ssh.
At this moment, it is not obvious which pid you want. So here is how I have figured it out before:
From pids.sh
#!/bin/bash
echo "Current pid: $$"
echo "Current process: $(ps -f $$)"
ppid=$(ps -o ppid= -p $$)
echo "Parent pid: $ppid"
echo "Paren process: $(ps -f $ppid)"
gppid=$(ps -o ppid= -p $ppid)
echo "Grand Parent pid: $gppid"
echo "Grand Paren process: $(ps -f $gppid)"
Current pid: 611
Current process: UID PID PPID C STIME TTY STAT TIME CMD
root 611 31197 0 06:41 pts/1 S+ 0:00 /bin/bash ./pids.sh
Parent pid: 31197
Paren process: UID PID PPID C STIME TTY STAT TIME CMD
root 31197 31195 0 04:55 pts/1 Ss 0:00 -bash
Grand Parent pid: 31195
Grand Paren process: UID PID PPID C STIME TTY STAT TIME CMD
root 31195 1216 0 04:55 ? Ss 0:00 sshd: root@pts/1
Also, the linux command pstree can help.