How to avoid PHP exec () using WSGI to execute a Python script?

I am now running a Python script from PHP using exec (), as I need to pass some dynamic variables from the website / MySQL to the command line. However, I would like to improve the speed and security of this operation, so I thought about using WSGI. I thought it would be possible to embed a Python script in a WSGI file that would use variables passed directly (or indirectly) from PHP ... but how can I do this? I have never used WSGI, so I don’t even know if this is a stupid question or not :)

+3
source share
1 answer

First, can you do all this in Python or PHP? Using multiple languages ​​is usually considered an anti-pattern. This does not mean that it is always a bad idea, but you should question why first, and only if you are convinced that a good idea will move forward.

As for the features of what you want to do, there are several options:

  • If you use Apache, you can use the function virtual()to issue a new request through Apache.

    It is assumed that you are using mod_php and mod_wsgi. Basically, you will create a query string for the variables you want to pass, and name it like this:

    virtual('path/to/python.py?'.$query);
    
  • Create your own PHP WSGI gateway.

    Basque, specify the WSGI specification in the library and call it explicitly from PHP.

  • exec() (, , ).

, , , . , . ...

+1

Source: https://habr.com/ru/post/1789985/


All Articles