473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1794

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.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.