Hi,
I am having problems when executing commands on remote computer/localhost from php.
Sometimes it happens that the response is not complete.
From the program:
$this->connection = ssh2_connect($this->host, $this->port, array('hostkey'=>'ssh-dss, ssh-rsa'))
ssh2_auth_password($this->connection,
$this->login,
$this->password)
//Running a program on machine
$command = "export SW_HOME='/opt/kabira/users/vbezakPAYGTW2'; export PATH=.:/usr/bin:/usr/local/bin:$SW_HOME/distrib/kabira/kts/scripts;switchadmin display agentpayment"
$stream_all = ssh2_exec($this->connection, $command, NULL);
$stderr_stream = ssh2_fetch_stream($stream_all, SSH2_STREAM_STDERR);
$stream = ssh2_fetch_stream($stream_all, SSH2_STREAM_STDIO);
stream_set_blocking($stderr_stream, true);
stream_set_blocking($stream, true);
while(($line = fgets($stream)) !== false) {
//flush();
array_push($results, $line);
}
fclose($stream);
fclose($stderr_stream);
fclose($stream_all);
Sometimes, the response arrives whole, sometimes not (only part or nothing is received).
I tried almost everything:
- stream_set_blocking to true/false.
- not using ssh2_fetch_stream, and directly doing fgets on stream_all,
- adding echo "END_OF_RESPONSE" to the command, and waiting for it,
- setting terminal to false, "xterm", or not setting it in ssh2_exec,
but nothing is working 100% correctly.
I am using (from phpinfo()):
PHP Version 5.2.9
ssh2 section:
SSH2 support enabled
extension version 0.11.0-dev
libssh2 version 1.1
banner SSH-2.0-libssh2_1.1
remote forwarding enabled
hostbased auth enabled
polling support enabled
publickey subsystem enabled
Does anyone have any idea what may be wrong?
Thank you very much
Vladimir
Problems with response from ssh2_exec
Moderator: General Moderators