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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化