472,799 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Python, WSGI, legacy web application

Howdy all,

I'm working on a web application that is starting to gain a lot of
back-end code written in Python. However, all the current interface
code is written in legacy PHP. I'd like to slowly introduce new
features as Python WSGI programs.

Is it possible to write a Python WSGI program that talks to a PHP
program as its "back end"? Where can I find out how to do this,
preferably with examples?

The ideal here is to keep all the existing code as is, but write
little or no new PHP code. Instead, iteratively change the interface,
replacing pieces of the monolithic legacy PHP interface with modular
WSGI programs over time.

--
\ "I don't know anything about music. In my line you don't have |
`\ to." -- Elvis Aaron Presley (1935-1977) |
_o__) |
Ben Finney

Nov 22 '06 #1
7 1751

Ben Finney wrote:
Howdy all,

I'm working on a web application that is starting to gain a lot of
back-end code written in Python. However, all the current interface
code is written in legacy PHP. I'd like to slowly introduce new
features as Python WSGI programs.

Is it possible to write a Python WSGI program that talks to a PHP
program as its "back end"? Where can I find out how to do this,
preferably with examples?

The ideal here is to keep all the existing code as is, but write
little or no new PHP code. Instead, iteratively change the interface,
replacing pieces of the monolithic legacy PHP interface with modular
WSGI programs over time.
Look at mod_python for Apache. If you use it correctly you can on a
page by page basis as need be, replace the existing PHP pages with
equivalents written using Python. You could do this by programming
right at the level of mod_python, or again, if done right by using WSGI
on top of mod_python. If you need to maintain compatibility of URLs,
you could even do things so that even though URLs use .php, that it
maps to Python code underneath, thus easing any transition.

If you are interested in this path, the mod_python mailing list may be
a good place to go to discuss the mod_python aspects of this. The
mod_python mailing list details are on the mod_python web site at
www.modpython.org.
Graham

Nov 23 '06 #2
Ben Finney wrote:

Is it possible to write a Python WSGI program that talks to a PHP
program as its "back end"? Where can I find out how to do this,
preferably with examples?
Perhaps:

http://pythonpaste.org/wphp/
http://blog.ianbicking.org/2006-wphp.html

Nov 23 '06 #3
"ToddG" <td*****@gmail.comwrites:
Ben Finney wrote:
Is it possible to write a Python WSGI program that talks to a
PHP program as its "back end"? Where can I find out how to do
this, preferably with examples?

Perhaps:

http://pythonpaste.org/wphp/
http://blog.ianbicking.org/2006-wphp.html
Looks good. Can anyone here tell any stories about using this for its
stated purpose?

Where would be the best place to ask further questions on this?

--
\ "Two paradoxes are better than one; they may even suggest a |
`\ solution." -- Edward Teller |
_o__) |
Ben Finney

Nov 23 '06 #4
"Graham Dumpleton" <gr*****@dscpl.com.auwrites:
Look at mod_python for Apache. If you use it correctly you can on a
page by page basis as need be, replace the existing PHP pages with
equivalents written using Python. You could do this by programming
right at the level of mod_python, or again, if done right by using
WSGI on top of mod_python. If you need to maintain compatibility of
URLs, you could even do things so that even though URLs use .php,
that it maps to Python code underneath, thus easing any transition.
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?

--
\ "Compulsory unification of opinion achieves only the unanimity |
`\ of the graveyard." -- Justice Roberts in 319 U.S. 624 (1943) |
_o__) |
Ben Finney

Nov 23 '06 #5
Ben Finney wrote:
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?
You can use FastCGI or SCGI too, with Apache, lighttpd or Cherokee. I
have a short description of different ways to run a WSGI app here:

http://pydap.org/docs/server.html

Though it's focused on a specific WSGI app I wrote it uses Paste
Deploy, so you can generalize it easily.

--Rob

Nov 23 '06 #6
Rob De Almeida wrote:
Ben Finney wrote:
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?

You can use FastCGI or SCGI too, with Apache, lighttpd or Cherokee.
I think the motivation behind suggesting an Apache solution was that
you'd be able to migrate the PHP resources you already have running in
Apache (I assume, since PHP can run in other places these days) to
mod_python whilst staying within the Apache environment, rather than
having to maintain a number of different environments at the same time.
In other words, you'd write your replacement resources using WSGI (or
whatever) on mod_python (for performance), CGI (for relative
simplicity), or some other connection technology, and then it'd just be
a matter of changing the various directives and having Apache figure it
out.

I know some people advocate proxying to a variety of backend servers,
and the Web obviously lends itself to flexible architectures in this
respect, but there are fairly good reasons for keeping the component
count low.

Paul

Nov 23 '06 #7
Paul Boddie wrote:
Rob De Almeida wrote:
Ben Finney wrote:
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?
You can use FastCGI or SCGI too, with Apache, lighttpd or Cherokee.

I think the motivation behind suggesting an Apache solution was that
you'd be able to migrate the PHP resources you already have running in
Apache (I assume, since PHP can run in other places these days) to
mod_python whilst staying within the Apache environment, rather than
having to maintain a number of different environments at the same time.
In other words, you'd write your replacement resources using WSGI (or
whatever) on mod_python (for performance), CGI (for relative
simplicity), or some other connection technology, and then it'd just be
a matter of changing the various directives and having Apache figure it
out.
Correct.

As example, imagine you have written a mod_python handler which itself
interprets how to map a URL to something to implement the URL. This
might map to a WSGI application or to some system of basic mod_python
handlers.

Within the .htaccess file of the directory where all your PHP files
live you could then write:

PythonHandler myphppagereplacementhandler | .php

At this point nothing will happen, but then one could do the following:

<Files index.php>
SetHandler mod_python
</Files>

For the one page called 'index.php' the mod_python handler would be
called instead of PHP. As a Python equivalent for each PHP page is
written, just need to trigger the mod_python handler to be used by
using the Files directive.

One could also have different handlers for each page and use Apache to
make the selection if wanted to:

<Files index.php>
SetHandler mod_python
PythonHandler myphppagereplacementshandler::index
</Files>

Now I am sure that some will say it looks messy, but as far as trying
to do a progressive replacement of pages and maintain URLs, it is
probably the quickest way. It should be said that any progressive
migration like this is likely to be a bit messy.

Don't like this, then another way using Apache might be to use
mod_rewrite to remap URLs to new URLs which use Python code. Using
mod_rewrite can be a pain though. Yet another way may be to use
mod_proxy to selectively forward URLs through to a separate back end
web server if you are Apache phobic and want to use a web server
written in pure Python.

Overall, Apache/mod_python has a lot to offer, but from what I have
seen most Python web frameworks simply uses it as a jumping off point
and not much else.

Graham

Nov 23 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phillip J. Eby | last post by:
PEP: 333 Title: Python Web Server Gateway Interface v1.0 Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/27 17:30:09 $ Author: Phillip J. Eby <pje at telecommunity.com> Discussions-To:...
2
by: matt | last post by:
Hi all- I'm trying to port an ajax spell-checker (http://www.broken-notebook.com/spell_checker/index.php) to use with the moin moin wiki and have been somewhat successful. (By successful I...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
7
by: Echo | last post by:
I am going to start working on a church website. And since I like python, I decided to use WSGI. However, I later found out about all the different CMS's in php. So I wondered if there where any in...
5
by: Adam Atlas | last post by:
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)?...
37
by: Michele Simionato | last post by:
At work we are shopping for a Web framework, so I have been looking at the available options on the current market. In particular I have looked at Paste and Pylons and I have written my...
5
by: walterbyrd | last post by:
I don't know much php either, but running a php app seems straight forward enough. Python seems to always use some sort of development environment vs production environment scheme. For...
8
by: jmDesktop | last post by:
I have been to the main python site, but am still confused. I have been using .net, so it may be obvious how to do this to everyone else. I am aware there are various frameworks (Django, Pylons,...
2
by: Michael Palmer | last post by:
On Sep 5, 9:56 pm, Sean Davis <seand...@gmail.comwrote: xmlrpc is the right idea, as it interfaces easily across languages.
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.