Python as replacement for PHP?
ej.at.wellkeeper at dot.com
Fri Feb 27 21:50:09 CET 2004
This is somewhat a NEWBIE question...
My company maintains a small RDBS driven website. We currently generate
HTML using PHP. I've hacked a bit in Python, and generally think it is a
rather cool language. I've done Perl and like it, there are a few features
of PHP I like but overall am not too excited about it. I have found PHP's
strtotime() function to be quite flexible and handy and we make liberal use
I have not yet really "dug-in" to Python - I have dabbled and hacked a
bit. I am advocating considering switching to Python for a number of
1) I think Python is cool.
2) We can do system administration type scripts (currently
implemented in Perl), web page generation (PHP), and (potentially)
client-side applications (including GUI's that make socket and/or external
HTTP requests) in one language.
3) Python's interactive interpreter makes it easy to try things out.
4) PyUnit - we would like to develop a robust set of tests and be
able to do regression testing. I'm not aware of a JUnit/PyUnit analog in
PHP. Are you?
5) Python has better code support for complex native data types
(e.g., tuples, dictionaries, sequences, etc. and being able to write these
directly in a hierarchical structure rather than building them up piecewise
with function calls and assignments as in PHP).
6) All the other standard evangeslistic points about why Python is
better than <your favorite language here>, some of which may be valid to us,
some probably not. To those that have used PHP: what am I potentially losing
that Python really can't replace?
So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points: (NOT Python evangelism please: I've already heard most of it, I've
espoused a pretty good dose myself - frankly, I'm willing to buy most of it,
but I've got a serious business decision to make here).
1) PHP seems to have a pretty good integration/driver with PostgreSQL.
If we were to switch to Python, what modules/drivers are available to talk
to PosgreSQL and is it as functional as PHP's support?
2) Is there a way to have our cake and eat it too? That is, rather than
being forced to ride one horse or another, can I ride both horses at once:
is there a way to integrate PHP and Python such that I could call PHP
functions from a Python script? I know you can always make system calls, and
it probably wouldn't be that difficult to call an external PHP script and
slurp up it's output from STDOUT, but my impression is that this is a pretty
expensive thing to do (relatively) compared to generating HTML from a single
script invocation. I'm asking if there exists some sort of single-process
integration (e.g., something akin to Java's "native" interface where a
program can schlep data back and forth between a Java environment and
3) Does Python have an analog to strtotime()? (For those not familiar
with that function, it converts a wide range of date formats as string into
time_t value. Can handle things like "now", "+24 hours", "-3 days",
"yesterday 06:00PM MST", "January 23, 2004", "2004-02-26 18:00:00 -07",
4) I am vaguely aware of Apache's modpython. We are currently running
apache, but I'm real green when it comes to configuring/running/managing
Apache. I don't really understand what all modpython does for me. Generally
allows Apache to foist off an HTTP request on a Python script to handle I
assume, but maybe some kind soul can better inform me about what all
modpython really does for me?
5) A PHP script can freely jump in and out of static HTML and script
code with <?php ?> tags. This is sometimes handy. Can you do the same thing
6) Debugging: I'm aware there is a debugger for Python - I haven't
really used it. Maybe there is a better way to do this using PHP, but right
now when a PHP script isn't working right, I'm reduced to print statements
and just re-running the script. Do you know a better way to do this in PHP?
If I were doing things in Python, is there an easy way to generate an HTTP
request from my browser, but stop the generating script and analyze it in a
7) This goes back to #2, but we are looking at purchasing a PHP graphing
package: http://www.aditus.nu/jpgraph/ If we could easily call PHP from
within Python, then I guess that is a no brainer: we can use the PHP
package. If not, then we are left answering the quesiton, can we call it as
a forked process, and if so, is that too expensive? Do you know of
comparable packages for Python?
I think that's it for now. Thank you for taking the time to read my post
and many thanks in advance to anyone who would be so kind as to reply.
(direct response to ej at wellkeeper dot com greatly appreciated).
More information about the Python-list