I'm trying to execute a bash script from php and getting its output in real time.
I am applying the answers found here:
However they are not working for me.
When I invoke the .sh script on this way, it works fine:
<?php
$output = shell_exec("./test.sh");
echo "<pre>$output</pre>";
?>
However, when doing:
<?php
echo '<pre>';
passthru(./test.sh);
echo '</pre>';
?>
or:
<?php
while (@ ob_end_flush()); // end all output buffers if any
$proc = popen(./test.sh, 'r');
echo '<pre>';
while (!feof($proc))
{
echo fread($proc, 4096);
@ flush();
}
echo '</pre>';
?>
I have no output in my browser.
I also tried to call the variable instead of the script in both cases, I mean:
<?php
$output = shell_exec("./test.sh");
echo '<pre>';
passthru($output);
echo '</pre>';
?>
This is my test.sh script:
#!/bin/bash
whoami
sleep 3
dmesg