duanjingsen7904 2016-02-22 12:42
浏览 44

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

I'm currently putting together a small web-based GUI to generate kickstart-scripts. I got a confirmation page that's sending the relevant data via POST to the PHP-page where the actual shell script is called to build the iso. So far it's working, but the page seems to execute the script before it outputs anything else (for example, the 'echo' I put in at the beginning of the page ...), and I'm absolutely clueless why. Would anyone care to enlighten me?

Here's the code to the PHP-page that's executing the shell script ...

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");
  • 写回答

1条回答 默认 最新

  • doufeiqiong3515 2016-02-22 16:42
    关注

    PHP scripts accessed via a browser are request-response, meaning all processing is done on the server prior to headers and content being sent to the client. This means you will not get a continually updating output like you would see on the command line. There is no way around this. Sorry.

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献