get screen id via ssh in php

186 Views Asked by At

I am trying to run a lengthy command from a remote server on php using screen, but i want to make sure that the screen is killed at the end of the command. So i am trying to use "echo $STY" to get the screen id and kill it that way. for some reason, this is not working. Any ideas:

ssh2_exec($conn, 'screen');
    $getscreen =ssh2_exec($conn, 'echo $STY');
    stream_set_blocking($getscreen, true);
    $stream_outA = ssh2_fetch_stream($getscreen, SSH2_STREAM_STDIO);
    $valA =fgets($stream_outA,160);
    $scrnids =explode('.',$valA);
    var_dump($scrnids);
    $killcommand = 'screen -X -S '.$scrnids[0].' kill';
       $stream = ssh2_exec($conn, $command);
       .....

    ssh2_exec($conn, $killcommand); 
    ssh2_exec($conn, 'exit'); //just in case
    unset($conn);

the var dump just outputs:

 array (size=1)
  0 => string '
  ' (length=1)
0

There are 0 best solutions below