简体   繁体   English

如何从PHP上的python脚本获取实时输入输出

[英]How to take real time input output from a python script on PHP

I want to take input from user through a html form, process it through a python script and print the output on html page. 我想通过html表单从用户那里获取输入,通过python脚本对其进行处理,然后在html页面上打印输出。 The problem is the whole python script is executed each time, while I want the script to give real time output for each input. 问题是每次都执行整个python脚本,而我希望脚本为每个输入提供实时输出。 How can I manage to do this ? 我怎样才能做到这一点?

Here is what I am doing so far. 到目前为止,这是我正在做的事情。

<?php
    $vout='';
    if(isset($_POST['submit']))
    {
        $vin=$_POST['input_text'];
        $vout=exec('python bot.py '.$vin);
    }
?>
<form method="post">
<label>
    BotIn: <input type="text" name="input_text">
</label>
<input type="submit" name="submit">
</form>
</br></br>
<label>
    <p>Bot: <?=$vout?></p>
</label>

The best way to solve your problem will be running simple python app using, let's say, Flask and hit to specific endpoint you'll make in it. 解决问题的最佳方法是使用Flask运行简单的python应用程序,然后点击要在其中创建的特定端点。 Everything then could take place through localhost, if you'll set it on the same machine. 如果您将其设置在同一台计算机上,那么一切都可以通过localhost进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM