簡體   English   中英

從php運行的bash腳本的進度欄

[英]Progress bar for a bash script running from php

在StackOverflow上人們的無價幫助下,我設法從php運行bash腳本。 現在一切運行正常,但是由於腳本需要花費幾分鍾才能結束,所以我希望看到進度。 在bash腳本中,有一些printf命令可輸出錯誤/成功消息。

作為php中的新手,我假設這些消息將在bash腳本中執行時出現。 但是盡管腳本完成了,但我沒有任何輸出。 我可以看到創建的文件,並且可以確定腳本已完成,但是在瀏覽器中看不到php的任何輸出。

腳本仍在運行時如何檢查進度? 為什么PHP似乎沒有結束?

以下是php腳本。

<?php

echo "<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
      <html xmlns=http://www.w3.org/1999/xhtml>
      <head>
      <meta http-equiv=Content-Type content=text/html; charset=UTF-8 />
      <title>Title</title>
      <link href=../style.css rel=stylesheet type=text/css>
      </head>
      <body topmargin=0 leftmargin=0>";
echo '<font color=blue>';

echo '------------------------------------------------------------- <br>';
echo 'Inicio de la generación manual de mapas de olas de calor<br>';
echo 'Este proceso tarda varios minutos<br>';
echo '-------------------------------------------------------------<br>';
echo date('h:i:s') . "\n";
$output = shell_exec('/home/meteo/www/RAMS/olas/generar-mapas.bash');
echo "<pre>".$output."</pre>";
echo '</font>';
echo '</body>';
echo '</html>';

?>

我已經在論壇上閱讀了一些有關php,Ajax和jQuery的帖子,以了解進度條,但我只知道一些非常基本的php。 是否有針對php新手的簡單解決方案? 謝謝你的幫助

shell_exec()阻塞直到子進程完成,請改用popen()

$p = popen('/home/meteo/www/RAMS/olas/generar-mapas.bash', 'r');
while(!feof($p)) {
    echo fgets($p);
    ob_flush();
    flush();
}
pclose($p);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM