Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing Python and PHP?

Tags:

python

php

apache

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 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.

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

like image 541
Axl Avatar asked Dec 29 '22 05:12

Axl


1 Answers

  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?

like image 56
Michael Ekoka Avatar answered Jan 07 '23 23:01

Michael Ekoka