This executes a predefined script on a remote host, and somehow retrieve variable values without affecting STDOUT
and STDERR
.
My idea was to encode the data in JSON, write it to a file, then read the data in a separate request.
The cons of this method are that:
- I would need to add the following code (
file_put_contents
) to the bottom of every script. - It requires a separate request (albeit, a pretty light request)
This is a dumbed down example, but inside the script to be run remotely:
<?php
$data = array(...);
$json = json_encode($data);
file_put_contents('tmp.json', $json);
On the local side:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('php script.php');
$json = $ssh->exec('cat tmp.json');
I'm just looking for some input or alternative ways of doing this.
$data
variable and add my SSH login info. I just excluded some sensitive information and information unrelated to the question. – Devon Apr 7 at 0:02echo
ed back to the client, and the additional data comes in via a separate stream (bu the same connection). – Snowbody Apr 7 at 17:00