1

I would like to render a file that has both PHP tags and Web2Py tags mixed together.

To do this, I would like the web server to pass the file through Web2Py, then PHP. I found a method to call PHP from Web2py via Python (based on this method for running PHP on top of django), but this method loses the benefits of any server optimizations from mod_php or FastCGI like caching and multi-threaded operation. A new process is created for each PHP request, which is very slow.

Is there a better way to efficiently render pages with both Web2Py(Python) and PHP tags in the same file? Note I am not looking for methods of serving PHP-only and Web2Py-only files from the same server/domain. I prefer solutions for Apache2 or Cherokee. I'm open to using other web servers, though.

Background info: I prefer to develop in Web2Py, but we have this pre-existing system written in PHP. I would like to augment the PHP system with some of Web2Py's features like auth authentication/user management and the T() internationalization object. Also it would make it much easier to port the PHP project to Web2Py if it could be done piecemeal. Since the PHP project consists of many files, it would greatly help if they did not need modification.

2 Answers 2

0

The best way to get around this is to separate out the legacy php bits and load them via asynchronous JavaScript calls, using ( for example ) jQuery. It may be very difficult to configure your web server to process the same page request through the two different environments, and even if you do get it working my guess is it would seriously degrade performance, as you already pointed out.

0

The CGI Interface (of PHP, Python, or whatever you use) takes input and transforms it to output. So attaching one to the other sequentially should be possible.

Unfortunately, I can’t give you any definite details on this. Let’s try:

Apache2s fcgid_module provides CGI.

FcgidInitialEnv      PHPRC "/path/to/php/conf"
FcgidWrapper         "/path/to/php/php-cgi" .php

Two options here:

  • A proper cgi-capable wrapper calling first one, then the other (python and php).
  • The webserver allows for cascading cgi wrappers or wsgi & cgi.

The doc on fcgid states “The directive can be used multiple times.”, but I’m not sure that includes calling multiple cgi scripts for the same file suffix.

Now, don’t know how you invode python. But wsgi is just an invocation interface as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .