Ian Bicking: the old part of his blog


I got the experimental version of WPHP working last night. This allows you to represent a PHP application as a WSGI application; you make wphp.PHPApp(base_dir), and it'll spawn a PHP/FastCGI subprocess and hand requests off there.

I asked a little while back about a FastCGI server-side/client module, which is what this uses, but no such thing existed. After trying really not very hard to write it myself, I emailed Allan Saddi to see if he was interested, and then he emailed me back an implementation the next day. So that was pretty sweet. From there, WPHP just handles starting the PHP process and fixing up the environment some (PHP requires the SCRIPT_FILENAME environmental variable, for instance, and we have to handle non-PHP files on our own).

This means that PHP applications can be embedded in Python systems. This may not seem that exciting, until you have interesting WSGI middleware. Authentication systems, templating, annotation and other kinds of middleware can be layed over the PHP output.

Next up for me: finishing some work to let you embed WSGI apps in Zope and vice versa.

Created 27 Jul '06
Modified 28 Jul '06


Thank you for all your wonderful work, Ian. You rock.

# Sergey

The start of the first sentence seems to be missing.

# Hamish Lawson

Indeed; not sure how that happened. Made a guess about what I was trying to say...

# Ian Bicking

Okay, now that sounds exciting! Mmmmm... what could we do with this?

# Michael Chermside

Got an existing WSGI project, and want to quickly add a forum or other existing PHP software (perhaps a bespoke application that you want to replace over time with a python one)?

Use this code with an existing WSGI dispatcher to let PHP handle part of your site. Even more excitingly, you could rewrite the PHP application to generate basic HTML (or XML) through its template system, then have your WSGI templating system producing the output for both PHP and python applications. A WSGI middleware application would be also able to do single sign-on for both sets of applications...

Heck, you could even wrap a Rails application.

All in all, a very good way of being able to add functionality to existing web applications, without having to touch any of its code. Good work, Ian!

# Jeremy

your WPHP app is being extremely helpful in my effort in integrating RoundCube (php based) into twisted.web2!

I had to patch line 370 in file fcgi_app.py:

header, value = line.split(':',1)

Otherwise headers with multiple : produce exceptions. For example:
"Expires: Thu, 01 Dec 1994 16:00:00 GMT"

Kind regards,
# DQ