Re: PHP hangs when exec'ing SSH

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm attempting to execute some things on remote servers using ssh, using a strictly limited account created for this express purpose. I set up passwordless key authentication from the user the web server runs as to the limited account on the remote server. I wrote some PHP code which calls:
system("ssh user@host mycommand", $result)


If I become the web-server user and run this via php from the command-line, everything works. The commands are executed remotely, and the expected HTML comes to standard-out.

If I run this through apache, I can verify that the authentication happens successfully, and the commands are run, but output to the browser hangs. No errors, nothing. I have attempted using shell_exec, and popen as well- both exhibit the same problems. I can run commands other than ssh without difficulty.

This is happening on suse linux 9.1, PHP 4.3.4. Any clues as to what may be happening?
>
Ross,
A couple of ideas:

- Here's your code: "system("ssh user@host mycommand", $result)"
You do realize that $result only contains the return code of the system call and not the actual output from the program called via system(), right?


- Do you have any sort of output buffering in the script?

- Have you tried using passthru() or backticks[1] instead of system()? Same results?

- Is it possible the ssh command on the remote host is sending the output to STDERR instead of STDOUT? I'm not sure that this makes sense since you say it is working via PHP CLI, but perhaps you are seeing the STDERR output along with the output of your script? This idea a longshot at best.

--
Jamie

1. http://us4.php.net/language.operators.execution

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux