Greetings.

I'm using PHP with the ssh2 functions (http://www.php.net/manual/en/ref.ssh2.php). I've noticed a bizarre behaviour on this:

1) When I run a simple command, as 'ls -la' I get the output of the server just fine.
2) When I run a 'apachectl status' I get the outuput fine too
3) But when I run a 'apachectl configtest' I receive an empty string as output, even if there are errors in the httpd.conf

Can someone please advice?

Here is my code:

<?php
function myig($message)
{
    die($message);
}

function mydbg($message, $language, $always_display)
{
    die("$message, $language, $always_display");
}

function mymac($packet)
{
    die($packet);
}

$sshMethods = array(
                    'kex' => 'diffie-hellman-group1-sha1',
                    'client_to_server' => array(
                                                    'crypt' => '3des-cbc',
                                                    'comp' => 'none'
                                                ),
                    'server_to_client' => array(
                                                    'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc',
                                                    'comp' => 'none'
                                                )
                );

$sshCallbacks = array('ignore' => 'myig', 'debug' => 'mydbg', 'macerror' => 'mymac');

$sshConn = ssh2_connect('myhost', 22, $sshMethods, $sshCallbacks) or die('SSH connection failed.');
ssh2_auth_password($sshConn, 'foo', 'bar');

$apacheStatus = ssh2_exec($sshConn, "apachectl configtest");
stream_set_blocking($apacheStatus, true);
$resultApache = stream_get_contents($apacheStatus);

print_r($resultApache); // Tried with echo too, with the same result, just to so you know

fclose($apacheStatus);
?>

TIA,

    Found the solution:

    Actually apachectl configtest writes its response to STDERR and not STDOUT, so a simple redirection solves the problem:

    $apacheStatus = ssh2_exec($sshConn, "apachectl configtest 2>&1");
    
      Write a Reply...