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 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化