开发者

Mixing Python and PHP?

I have some Python scripts that I run on my desktop now for cutting up files. I want to put them on the web and wr开发者_开发技巧ite 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.

I know a decent amount of PHP, but I do not see:

  1. How to mix PHP and Python programmatically

  2. Is it possible to have a webpage in python that can just call the python script? Can one have a GUI page that is like zzz.com/text.py as example


  1. For http requests, you need to set your web server to hand over certain request to PHP and others to Python. From within PHP's scripts, if you need to call some Python executable scripts, use one of PHP's shell functions. e.g. exec()

  2. Yes it is possible. The djangobook is a nice tutorial that covers this in one of the earlier chapters. It shows you how to run python as a cgi or with 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. My experience tells me that there are probably more cases where a PHP app needs some Python support rather than the reverse.

If the supporting language can do everything that the main language does, what's the point of using the main language?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜