$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
/* if you want to execute script from a different directory then use commands in same line separated
by ';', that is required in php.
In below second command '&' will do the magic to run command forever.
*/
$stream = ssh2_exec($connection, 'cd httpdocs/subdir/dir; /path/to/php server.php &');
$stream = ssh2_exec($connection, 'ps aux | grep server.php');
// printing ssh output on screen
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo stream_get_contents($stream_out);
// closing ssh connection
$stream = ssh2_exec($connection, 'exit');
unset($connection);