PHP 和 Python 等不同语言之间的多重处理
我之前问过一个关于如何在 Python 中进行多重处理的问题(尽管我在前一个问题中没有使用“多重处理”这个词,因为我不确定我是否在问这个问题)。
现在我想知道当涉及不止一种语言时如何进行多重处理,特别是如果您有一个调用 Python 脚本的 PHP 脚本。在这种情况下,如何让 PHP 脚本和 Python 脚本同时进行多进程,并在多进程时相互通信(来回发送变量)?
I asked a question before about how to do multiprocessing in Python (although I did not use the word multiprocessing in the former question, because I was not sure I was asking about that yet).
Now I am wondering how to do multiprocessing when you have more then one language involved, particularly if you have a PHP script that calls a Python script. In that case how can you have both the PHP script and the Python script multiprocess, and communicate with each other (send variables back and forth) as they multiprocess?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是通过网络服务。您可以在 Web 服务器上放置一个 PHP 进程,并多次运行和调用 Python Web 服务(使用 CherryPy)。您可以使用标准对象表示法(例如 JSON)传递变量,PHP 和 Python 都可以有效地编码/解码。
您还可以通过 Python 服务多次调用 PHP 服务来执行相反的操作。
在这两种情况下,由于您受到一定数量的并发连接的限制,因此您无需担心自己处理线程。
One way to this would be though web services. You could have a PHP process sitting on a web server and running and calling a Python web service (using CherryPy) multiple times. You would pass variables using a standard object notation such as JSON which can be efficiently encoded/decoded by both PHP and Python.
You could also do the reverse of this with a Python service making multiple calls to a PHP service.
In both cases, since you're limited by a certain number of concurrent connections you don't need to worry about handling the threads yourself.