PHP和Python之间的通信 [英] Communication between PHP and Python

查看:665
本文介绍了PHP和Python之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个Web界面对一些Python脚本。事情是我必须使用PHP(而不是CGI)和一些我执行脚本需要相当长的时间来完成:5-10分钟。是否有可能为PHP与脚本交流和展示某种进展情况?这应该允许用户使用网页上作为任务运行,并显示在此期间一些状况或只是一个消息,当它的完成。

目前使用exec()和在完成我处理输出。服务器在Windows机器上运行,因此pcntl_fork将无法正常工作。

以后编辑: 使用其他的PHP脚本使用AJAX饲料的主要页面的信息似乎并没有工作,因为服务器杀死它(达到最大的执行时间,我真的不希望增加这一点,除非必要的)

我在想基于socket通信,但我看不出我的情况是这样的有用的(一些提示,也许?

感谢您

解决方案

您想要的的进程间通信的。套接字是我想到的第一件事情;你需要一个插座设立的的在PHP连接(在同一台计算机上),并成立了一个插座的连接的在Python监听套接字和发送的是它的状态。

看一看从Python文档此套接字编程概述和的the Python的插槽模块的文档(尤其是在最后的例子)。我敢肯定,PHP也有类似的资源。

一旦你得到了你想要的建立和需要帮助,随便问一个的的计算器(如果它尚未回答)。<新的问题/一个更具体的想法P>

I'm trying to build a web interface for some python scripts. The thing is I have to use PHP (and not CGI) and some of the scripts I execute take quite some time to finish: 5-10 minutes. Is it possible for PHP to communicate with the scripts and display some sort of progress status? This should allow the user to use the webpage as the task runs and display some status in the meantime or just a message when it's done.

Currently using exec() and on completion I process the output. The server is running on a Windows machine, so pcntl_fork will not work.

LATER EDIT: Using another php script to feed the main page information using ajax doesn't seem to work because the server kills it (it reaches max execution time, and I don't really want to increase this unless necessary)

I was thinking about socket based communication but I don't see how is this useful in my case (some hints, maybe?

Thank you

解决方案

You want inter-process communication. Sockets are the first thing that comes to mind; you'd need to set up a socket to listen for a connection (on the same machine) in PHP and set up a socket to connect to the listening socket in Python and send it its status.

Have a look at this socket programming overview from the Python documentation and the Python socket module's documentation (especially the examples at the end). I'm sure PHP has similar resources.

Once you've got an more specific idea of what you want to build and need help, feel free to ask a new question on StackOverflow (if it isn't already answered).

这篇关于PHP和Python之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆