douling0053
2014-04-07 15:58
浏览 368
已采纳

PHP从执行二进制文件获取输出

I'm trying to figure out if it is possible to do the following using php:

I have a website that uses php to display database information. Now, I'd like to be able to implement another capability and that is I'd like to write a new php web page and launch a thread which executes a binary and have the output be displayed on the web page live (if possible).

I think I need to use ajax to be able to refresh the page in order to show "live output" in the page.

The problem I'm having is figuring out if I can launch a thread that executes a binary and display the output on the webpage. Is that possible? If so, how?

图片转代码服务由CSDN问答提供 功能建议

我正在试图弄清楚是否可以使用php执行以下操作:

我有一个使用php显示数据库信息的网站。 现在, 我希望能够实现另一个功能,那就是我想编写一个新的php网页并启动一个执行二进制文件的线程并将输出显示在网页上(如果可能的话) )。

我想我需要使用ajax才能刷新页面以便在页面中显示“实时输出”。
\ n

我遇到的问题是弄清楚我是否可以启动执行二进制文件的线程并在网页上显示输出。 那可能吗? 如果是这样,怎么样?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpjtn48868 2014-04-07 21:06
    已采纳

    You can do like this, use jquery plugin, to do ajax and load result of script.php to any section of your html page.

    script.php

    <?php
         echo exec('date'); //type command to be executed here.
    ?>
    

    page.html

    <html>
        <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js" >
        </script>
        <script type="text/javascript">
        $(document).ready(function(){
            setInterval(executeScript,1000);
        });
    
        function executeScript(){
            $("#result").load("script.php");
        }
        </script>
    
    </head>
    <body>
        <div id="result"> command result will come here.. </div>
    </body>
    </html> 
    

    It will call script.php at every second and its result will be shown in <div id="result"> </div>

    You can also use jQuery ajax .post(), .get() or .ajax() to pass some argument to script and get response accordingly.

    点赞 评论
  • douchuanhan8384 2014-04-07 16:06

    The way to do this kind of thing is usually to execute the binary and disown it but have its output written to a file as it runs.

    Then your ajax system literally downloads that text file for display.

    点赞 评论

相关推荐 更多相似问题