|
Posted by Ross Becker on 10/13/94 11:10
I actually do care about the return code from the program, as well as
knowing that the program executed and completed successfully, so
background execution is not a valid option.
I tried using system("ssh user@host mycommand > /dev/null 2>&1") and got
the same results.
You are correct that I am using "su" to become the same user that the
web server runs under, after temporarily changing the password file to
give said user a valid shell. I can verify that the shell does not
affect whether this problem occurs or not, and I have determined that
the SSH process is not left lying around after it executes- The remote
command is run, ssh executes, PHP simply never comes back.
Bug link is here: http://bugs.php.net/bug.php?id=22946
At this point I'd love to hear from anyone running a different version
of PHP, OS, or Apache who can actually execute this to find out if they
experience results which are the same or different.
--Ross
Jamie Alessio wrote:
>> There is no output to stderr or stdout from the script being executed.
>> All I care about are the side-effects of running this remote program.
>> If something fails, a numeric error-code will be returned.
>>
> Ross,
> Since you don't care about the output from the program can you start the
> process in the background so that PHP won't wait on it?
>
> system("ssh user@host mycommand &");
>
> and based on the notes at From http://us4.php.net/system you might need
> something like:
> system("ssh user@host mycommand > /dev/null 2>&1 &");
>
> I think this gives up your ability to check on whether the script was
> command actually ran successfully though which might not be acceptable
> for your situation.
>
> Some more random ideas...
>
> - Could ssh possibly be relying on some environment variables to behave
> properly that are available on the command line that aren't available
> when running system() via the web server? I'm assuming you "become the
> webserver" by doing something like "sudo apache" or "sudo nobody" in
> which case you'd have environment variables lying around that won't
> exist for the apache process. A quick look at "man ssh" lists a bunch of
> environment variables it uses/sets, but none of them look like obvious
> culprits.
>
> > I actually located a bug filed for this in early 2003 reguarding this
> > happening on SuSE 8.1 with PHP 4.3.1, but the developers dropped it
> > because there was no feedback from the user.
> >
> URL to the bug report?
>
> --
> Jamie
>
>> I have tried this using: system(), shell_exec() - same as backtick
>> operator, and popen(). I have tried this using an external shell
>> script which calls the ssh executable. All methods get the same
>> results. The program on the remote host is successfully executed, but
>> PHP never comes back if it is operating under the web server. Also
>> note that I became the same user that the web server runs as to
>> execute the script under the PHP CLI.
>>
>> I actually located a bug filed for this in early 2003 reguarding this
>> happening on SuSE 8.1 with PHP 4.3.1, but the developers dropped it
>> because there was no feedback from the user.
>>
>> My worry is that there's also another bug reguarding executing SSH
>> that the developers closed as bogus claiming it was an SSH problem,
>> and pointing to an FAQ on the openssh site saying that SSH can hang
>> due to not knowing if there's further output coming from the program.
>> I'm hoping that this isn't their answer to my problem, because I can
>> demonstrate that it all works when PHP runs in CLI mode.
>>
>> --Ross
>>
>> Jamie Alessio wrote:
>>
>>>> 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
>>
>>
>>
[Back to original message]
|