Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Retrieving Apache command line output |
|
Author |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
Posted: Mon 01 Nov '21 18:49 Post subject: Retrieving Apache command line output |
|
|
Hi,
With the PHP script below, there is no problem retrieving the results from Apache on the command line:
Code: |
$command = 'CMD /D /C '.$c_apacheExe.' -t -D DUMP_VHOSTS';
ob_start();
passthru($command);
$output = ob_get_contents();
ob_end_clean();
|
This works very well for other commands like:
Code: |
$command = 'CMD /D /C '.$c_apacheExe.' -t -D DUMP_MODULES';
$command = 'CMD /D /C '.$c_apacheExe.' -t -D DUMP_INCLUDES';
$command = 'CMD /D /C '.$c_apacheExe.' -t -D DUMP_RUN_CFG';
and so on...
|
But, strangely, it doesn't work for the command:
Code: | $command = 'CMD /D /C '.$c_apacheExe.' -t'; |
that run syntax check for config files whether without errors (Syntax OK) or with errors, the result ($output) is hopelessly empty.
After many tests, verifications, research, it appears that even without errors in the configuration files the result is always sent to STDERR and not to STDOUT.
In a Windows command window, STDOUT and STDERR are "mixed up", so you see everything.
So I had to find a way to retrieve "at the same time" the displays of STDOUT and STDERR by a procedure using proc_open().
I don't know if this is the best way, but it works!
Code: |
$command = $c_apacheExe.' -t';
$descriptorspec = array(
0 => array('pipe', 'rb'), // stdin
1 => array('pipe', 'wb'), // stdout
2 => array('pipe', 'wb') // stderr
);
$process = proc_open(escapeshellarg($command), $descriptorspec, $pipes);
$output = '';
while (!feof($pipes[1])) {
foreach($pipes as $key => $pipe) {
$line = stream_get_line($pipe,0);
if($line !== false ) $output .= $line."\n";
}
}
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
|
And in $output, there is either 'Syntax OK' or errors if there are any. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 03 Nov '21 23:47 Post subject: |
|
|
httpd -S runs all that check at once.
I wonder why you parse that? |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
|
Back to top |
|
|
|
|
|
|