[英]PHP to load an HTML page while running an external script
在重定向到index.html
之前,我需要運行一個index.php
腳本,該腳本調用一個需要花費幾秒鍾運行的外部腳本。 php腳本是否可以同時將相同的index.html
加載到瀏覽器中,以使屏幕不出現空白? 如果沒有,將如何處理呢? 我最大的努力是:
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile("index.html");
echo $doc->saveHTML();
shell_exec('./shellscript.sh');
header('Location: index.html');
exit;
?>
無法加載:
Warning: DOMDocument::loadHTMLFile(): Tag nav invalid in index.html, line: 33 in {pathto}/index.php on line 3
index.html的這一行是- <nav class="navbar navbar-inverse navbar-fixed-top">
感謝您的協助。
這當然是可能的。 您可以關閉連接並隨后運行命令。 這避免了shell_exec
阻塞處理的問題。
使它工作起來有點棘手,但這有點像:
ignore_user_abort(true); // prevent the PHP script from being killed when the connection closes
header("Location: /index.html");
header("Connection: Close");
flush();
// the connection should now be closed, the user is redirected to index.html
shell_exec('./shellscript.sh');
如果您還發送內容,則可能需要發送Content-Length
標頭。 如果您正在使用會話,請確保使用session_close()
關閉會話。 您還應該刷新所有輸出緩沖區。
您收到的DOMDocument錯誤是無關的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.