doutangshuan6473 2018-05-13 14:10
浏览 238

从php调用的长时间运行的python脚本的输出返回未显示在网页上

I am simply calling python script from my php program and I need to display the output return from python script to webpage. I am new to this, so I tried many ways to get the output return,

1.

$command = escapeshellcmd('python script.py "ab" "cd" ');
$output = shell_exec($command);

2.

$output = shell_exec('python script.py "ab" "cd" ');
print $output;

3.

$command = system('python script.py "ab" "cd" ',$output);
echo "output is ".$output;
echo "command is".$command;

4.

$command = passthru ('python script.py "ab" "cd" ');
$output = shell_exec($command);
echo $output;

5.

exec('python script.py "ab" "cd" ', $output, $return_var);
echo $output;
echo $return_var;

If time taken taken by python script is less, then I able to get the output return to my php program and able to display on my web page.

print "Hello"
print "world"

But when my python program is calling any background process, which taking more time and giving output after few seconds, then that parts are not returning to the php program.

print "Hello"
returned_value=subprocess.check_output('ssh -p 29418 xyz.com --format=JSON', shell=True)
print returned_value

I tried to include sleep in php program but it is not helping as output is already returned. Some posts suggested to use Ajax Whether that is the only and correct way to solve this question?

Thanks in advance for your help or suggestion.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
    • ¥15 onvif+openssl,vs2022编译openssl64
    • ¥15 iOS 自定义输入法-第三方输入法
    • ¥15 很想要一个很好的答案或提示
    • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
    • ¥15 怀疑手机被监控,请问怎么解决和防止
    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区