简体   繁体   English

混合Python和PHP?

[英]Mixing Python and PHP?

I have some Python scripts that I run on my desktop now for cutting up files. 我现在在桌面上运行一些Python脚本来切割文件。 I want to put them on the web and write a simple front-end in PHP where a user uploads a file and it is passed as an argument to a python script on the web server and it is written out in chunks and the user can re-download the chunks. 我想把它们放在网上并在PHP中编写一个简单的前端,用户上传文件,然后将它作为参数传递给Web服务器上的python脚本,并以块的形式写出来,用户可以重新编写 - 下载块。

I know a decent amount of PHP, but I do not see: 我知道有相当数量的PHP,但我没有看到:

  1. How to mix PHP and Python programmatically 如何以编程方式混合PHP和Python

  2. Is it possible to have a webpage in python that can just call the python script? 有可能在python中有一个可以调用python脚本的网页吗? Can one have a GUI page that is like zzz.com/text.py as example 可以有一个GUI页面,例如zzz.com/text.py

  1. For http requests, you need to set your web server to hand over certain request to PHP and others to Python. 对于http请求,您需要将Web服务器设置为将某些请求移交给PHP,将其他请求移交给Python。 From within PHP's scripts, if you need to call some Python executable scripts, use one of PHP's shell functions. 从PHP的脚本中,如果需要调用一些Python可执行脚本,请使用PHP的shell函数之一。 eg exec() 例如exec()

  2. Yes it is possible. 对的,这是可能的。 The djangobook is a nice tutorial that covers this in one of the earlier chapters. djangobook是一个很好的教程,在前面的一章中介绍了这一点。 It shows you how to run python as a cgi or with apache. 它向您展示了如何将cthon作为cgi或apache运行。

On a personal note, if you have time to dig deeper into Python, I'd strongly encourage you to do the whole thing in it, rather than mix things with PHP. 从个人角度来说,如果你有时间深入研究Python,我强烈建议你完成整个过程,而不是用PHP混合。 My experience tells me that there are probably more cases where a PHP app needs some Python support rather than the reverse. 我的经验告诉我,可能有更多的情况,PHP应用程序需要一些Python支持而不是相反。

If the supporting language can do everything that the main language does, what's the point of using the main language? 如果支持语言能够完成主要语言所做的一切,那么使用主要语言有什么意义呢?

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

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