PHP:在屏幕输出之前运行的shellscript


php: shellscript running before screen-output

我目前正在组装一个基于 Web 的小型 GUI 来生成 kickstart-script。我得到了一个确认页面,该页面通过 POST 将相关数据发送到 PHP 页面,在该页面中调用实际的 shell 脚本来构建 iso。到目前为止,它正在工作,但页面似乎在输出任何其他内容之前执行脚本(例如,我在页面开头输入的"echo"......),我完全不知道为什么。有人愿意开导我吗?

这是执行 shell 脚本的 PHP 页面的代码......

echo 'Generating your ISO; this might take a while...';
sleep(20);
if (!isset($_POST['auth'])) {
        $ad = 'N';
        }
else {
        $ad = 'Y';
}
if (!isset($_POST['oracle'])) {
        $oracle = 'N';
        }
else {
        $oracle = 'Y';
        }
if ((!isset($_POST['ip'])) or (!isset($_POST['hostname'])) or (!isset($_POST['rhsel'])) or (!isset($_POST['submit'])) or (!isset($_POST['gw'])) or (!isset($_POST['nm']))) {
        die('Please use the correct form !');
}
if (isset($_POST['ip'])) {
        $ip = trim($_POST['ip']);
        }
if (isset($_POST['gw'])) {
        $gw = trim($_POST['gw']);
        }
if (isset($_POST['nm'])) {
        $nm = trim($_POST['nm']);
        }
if (isset($_POST['hostname'])) {
        $hostname = trim($_POST['hostname']);
        }
if (isset($_POST['rhsel'])) {
        $rhsel = $_POST['rhsel'];
        }
passthru("/usr/bin/sudo /data/skripte/webconfig.sh $rhsel $oracle $ad $ip $gw $nm $hostname 2>&1");
通过

浏览器访问的PHP脚本是请求-响应,这意味着在将标头和内容发送到客户端之前,所有处理都在服务器上完成。这意味着您不会像在命令行上看到的那样获得不断更新的输出。这是没有办法的。不好意思。