简体   繁体   English

通过PHP运行Python脚本

[英]Running Python script through PHP

It is a follow-up a question to my earlier post. 这是我先前帖子的后续问题。

I have developed a chat program using twisted in Python. 我开发了一个使用Python twisted的聊天程序。 I would like to integrate into a PHP script and be able to run through the browser. 我想集成到PHP脚本中并能够通过浏览器运行。

The chat program would open a HTML window. 聊天程序将打开一个HTML窗口。

I could run it using PHP5 command in the terminal and is working fine. 我可以在终端中使用PHP5命令运行它,并且工作正常。 However, when I call the PHP script through the browser it does not work. 但是,当我通过浏览器调用PHP脚本时,它不起作用。

Any idea what is missing. 任何想法都缺少。

EDIT : I am not getting any error on the browser, however, the python script is not running , 编辑:我在浏览器上没有任何错误,但是,python脚本未运行,

Here is my PHP code : 这是我的PHP代码:

$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 谢谢基兰

This doesn't make sense. 这没有道理。 The PHP script runs on the web server. PHP脚本在Web服务器上运行。 It generates some output which gets sent to the web browser. 它生成一些输出,并将其发送到Web浏览器。 Then the interaction is over until the web browser issues a new request. 然后,交互结束,直到Web浏览器发出新请求为止。

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. 通过编写运行Python程序的PHP程序,您将无法在Web浏览器中运行Python聊天程序。 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. Python程序大概需要获取输入(例如,用户要发送到聊天会话的消息是什么?),而当您像这样运行它时却无法做到这一点。

To develop a web-based chat system, the chat application actually needs to be aware that it's going to run in a browser. 为了开发基于Web的聊天系统,聊天应用程序实际上需要知道它将在浏览器中运行。

Take a look at the Nevow chat tutorial for one example of how you might go about developing this application. 查看Nevow聊天教程 ,了解如何开发此应用程序的一个示例。

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

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