drv13270 2013-05-08 10:08
浏览 32

通过PHP运行Python脚本

It is a follow-up a question to my earlier post.

I have developed a chat program using twisted in Python. I would like to integrate into a PHP script and be able to run through the browser.

The chat program would open a HTML window.

I could run it using PHP5 command in the terminal and is working fine. However, when I call the PHP script through the browser it does not work.

Any idea what is missing.

EDIT : I am not getting any error on the browser, however, the python script is not running ,

Here is my PHP code :

$unique_no = 1234;
$unique_name = "Kiran";

$command = '/usr/bin/python /var/www/php_program/chat.py ' . $unique_no  . ' ' . $unique_name ;

shell_exec($command);

Thanks Kiran

  • 写回答

1条回答 默认 最新

  • du3669 2013-05-08 11:26
    关注

    This doesn't make sense. The PHP script runs on the web server. It generates some output which gets sent to the web browser. Then the interaction is over until the web browser issues a new request.

    You won't be able to run a Python chat program in a web browser by writing a PHP program that runs the Python program. The Python program presumably needs to get input (for example, what message does the user want to send to the chat session?) and it can't do that when you're running it like this.

    To develop a web-based chat system, the chat application actually needs to be aware that it's going to run in a browser.

    Take a look at the Nevow chat tutorial for one example of how you might go about developing this application.

    评论

报告相同问题?

悬赏问题

  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图