Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

replaced http://us2.php.net with https://www.php.net
Source Link

First off, can you do it all in either Python or PHP? Using multiple languages is normally seen as an anti-pattern. That's not to say it's always a bad idea, but you should be questioning why first, and only then if you're convinced it's a good idea move forward.

As far as the specifics of what you want to do, there are a few options:

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

    This is assuming that you are using mod_php and mod_wsgi. Basically, you'd build up a query string for the variables you want to pass, and call it like:

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

    Bascially, code the WSGI spec into a library, and call it explicitly from within PHP.

  3. Stick to calling it from exec() (which will likely be the best option for now).

The thing that you have to consider is that there's overhead inherent to cross-including between languages. You'll never get over that, it's just the nature of the beast. So instead, I'd suggest keeping the entire request inside of one environment, and dealing with it in the entirety in that environment...

First off, can you do it all in either Python or PHP? Using multiple languages is normally seen as an anti-pattern. That's not to say it's always a bad idea, but you should be questioning why first, and only then if you're convinced it's a good idea move forward.

As far as the specifics of what you want to do, there are a few options:

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

    This is assuming that you are using mod_php and mod_wsgi. Basically, you'd build up a query string for the variables you want to pass, and call it like:

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

    Bascially, code the WSGI spec into a library, and call it explicitly from within PHP.

  3. Stick to calling it from exec() (which will likely be the best option for now).

The thing that you have to consider is that there's overhead inherent to cross-including between languages. You'll never get over that, it's just the nature of the beast. So instead, I'd suggest keeping the entire request inside of one environment, and dealing with it in the entirety in that environment...

First off, can you do it all in either Python or PHP? Using multiple languages is normally seen as an anti-pattern. That's not to say it's always a bad idea, but you should be questioning why first, and only then if you're convinced it's a good idea move forward.

As far as the specifics of what you want to do, there are a few options:

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

    This is assuming that you are using mod_php and mod_wsgi. Basically, you'd build up a query string for the variables you want to pass, and call it like:

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

    Bascially, code the WSGI spec into a library, and call it explicitly from within PHP.

  3. Stick to calling it from exec() (which will likely be the best option for now).

The thing that you have to consider is that there's overhead inherent to cross-including between languages. You'll never get over that, it's just the nature of the beast. So instead, I'd suggest keeping the entire request inside of one environment, and dealing with it in the entirety in that environment...

Source Link
ircmaxell
  • 165.6k
  • 36
  • 269
  • 316

First off, can you do it all in either Python or PHP? Using multiple languages is normally seen as an anti-pattern. That's not to say it's always a bad idea, but you should be questioning why first, and only then if you're convinced it's a good idea move forward.

As far as the specifics of what you want to do, there are a few options:

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

    This is assuming that you are using mod_php and mod_wsgi. Basically, you'd build up a query string for the variables you want to pass, and call it like:

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

    Bascially, code the WSGI spec into a library, and call it explicitly from within PHP.

  3. Stick to calling it from exec() (which will likely be the best option for now).

The thing that you have to consider is that there's overhead inherent to cross-including between languages. You'll never get over that, it's just the nature of the beast. So instead, I'd suggest keeping the entire request inside of one environment, and dealing with it in the entirety in that environment...

default

AltStyle によって変換されたページ (->オリジナル) /