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

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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器