This is a discussion on Python as replacement for PHP? within the PHP Language forums, part of the PHP Programming Forums category; This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 of it. 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 reasons: 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 "native" C)? 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", etc.) 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 with Python? 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 Python debugger? 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). -ej |
|
|||
|
Erik Johnson wrote:
> 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 > of it. > 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). When it comes to dynamic, DB driven sites, PHP is the only way to go. Python is not even close to being suited for this task. PHP claims to be a general-purpose language, but I do not know anyone who uses it for anything other than dynamic Web programming. A serious business decision? PHP would be the only winner here. You should not even be considering another language for this, it borders on stupidity. We use Python & C for backend processing, systems administration and other general programming tasks, but the front-end (the Websites) are pure PHP. |
|
|||
|
With total disregard for any kind of safety measures "Erik
Johnson" <ej.at.wellkeeper@dot.com> leapt forth and uttered: > 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? > SimpleTest: http://www.lastcraft.com/simple_test.php PHPUnit (1):http://www.students.cs.uu.nl/people/voostind/index.php? page=software PHPUnit (2):http://pear.php.net/package/PHPUnit PHPUnit (3):http://phpunit.sourceforge.net/ Having three test suites all called PHPUnit is a tad confusing... -- Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/ |
|
|||
|
Erik> 1) PHP seems to have a pretty good integration/driver with Erik> PostgreSQL. If we were to switch to Python, what Erik> modules/drivers are available to talk to PosgreSQL and is it as Erik> functional as PHP's support? I use psycopg and like it. There are a couple others as well. Erik> 3) Does Python have an analog to strtotime()? (For those not Erik> familiar with that function, it converts a wide range of date Erik> formats as string into time_t value. Can handle things like Erik> "now", "+24 hours", "-3 days", "yesterday 06:00PM MST", Erik> "January 23, 2004", "2004-02-26 18:00:00 -07", etc.) Marc-Andre Lemburg's mxDateTime might be the closest you'll get to such wide ranging formats. Erik> 4) I am vaguely aware of Apache's modpython. We are currently Erik> running apache, but I'm real green when it comes to Erik> configuring/running/managing Apache. I don't really understand Erik> what all modpython does for me. Generally allows Apache to Erik> foist off an HTTP request on a Python script to handle I Erik> assume, but maybe some kind soul can better inform me about Erik> what all modpython really does for me? It essentially avoids process creation and Python startup overhead. Both can be significant performance barriers on heavily loaded systems. Erik> 5) A PHP script can freely jump in and out of static HTML and Erik> script code with <?php ?> tags. This is sometimes handy. Can Erik> you do the same thing with Python? There are lots of different Python-based templating systems. I like Quixote. It's roughly the inverse of the way most systems do the HTML/<language> mind-meld. Instead of Python-in-HTML it's HTML-in-Python. There are other systems with which I am not aware. Cheetah and PSP come to mind. Erik> 6) Debugging: I'm aware there is a debugger for Python - I haven't Erik> really used it. Maybe there is a better way to do this using Erik> PHP, but right now when a PHP script isn't working right, I'm Erik> reduced to print statements and just re-running the script. Do Erik> you know a better way to do this in PHP? If I were doing Erik> things in Python, is there an easy way to generate an HTTP Erik> request from my browser, but stop the generating script and Erik> analyze it in a Python debugger? Inserting print statements is a pretty common debugging technique in Python as well. Also, take a look at the cgitb module. Skip |
|
|||
|
"Erik Johnson" <ej.at.wellkeeper@dot.com> wrote in message
news:403fa54b@news.zianet.com... > This is somewhat a NEWBIE question... > (snip) > 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 > reasons: > > 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? > > (snip) > > -ej > > You should use what is best for you, but trying to settle on one laguage for everthing is not a good idea, you will end uplocking yourself into more code than you need sometimes. Python is gread for server stuff, and GUI stuff, but for dynamic intergration of html/script, PHP wins hands down. Now I also use PHP for everything else (except GUI stuff) on servers, almost all of my shell scripts are in php, along with autoresponders, mail filters, data backup servers, etc.. But again, use what is quick/fast/simple to implment for you. I use to use perl for everthing under the sun, then slowly moved to php, not becouse it was cool, but rather easier to set up, and with added functions designed for dynamic site ingration. You also need to look at what each language was desgined for, sure I can write a dynamic web page in bash or korn, but why? Perl was written to do large extraction and reporting of text files, Python was written as a server language, PHP was design specificly for dynamic/integration of web pages. Ok, I'm done now. -- Mike Bradley http://www.gzentools.com -- free online php tools |
|
|||
|
> 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, My approach is to use PHP with the Smarty templating system for the web front end. All program logic and "heavy" lifting (and even the light lifting) is done by a backend Python program accessed via XML-RPC. That lets me use each language for what it is best and most productive at. Testing is easier since you can do it via XML-RPC. Roger |
|
|||
|
On Fri, 27 Feb 2004 13:50:09 -0700,
Erik Johnson <ej.at.wellkeeper@dot.com> wrote: > 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? There are several; for some reason I don't really understand, there are multiple Python/PostgreSQL modules. Most of them will support the standard DB-API described in PEP 249. Personally I use PygreSQL with Quixote as the web framework. Note that I'm one of the developers on a Python web framework called Quixote (www.quixote.ca), so my answers are slanted in that direction. If you're in the Washington DC area, I'll be giving a Quixote tutorial next weekend at a Linux user group meeting; see novalug.tux.org for meeting details. > 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", > etc.) mxDateTime has an extensive parsing module. There's a PEP for adding date parsing to core Python, but it may not get done for 2.4. > 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 It embeds a Python interpreter in the Apache daemon, so you can intersperse Python processing in Apache's request processing. There's going to be a mod_python tutorial at the upcoming PyCon conference; again, if you're in the DC area you might consider going in order to talk to existing Python/web developers. Note that embedding the interpreter in Apache isn't a requirement; you can also run applications using SCGI, or FastCGI instead. You'd have to carry out benchmarks to see which one ends up running fastest for your application. > 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 > with Python? There are various templating packages available for Python, such as Cheetah (vaguely PHPish), ZPT (XML-based), or PTL (part of Quixote). Personally I don't find embedding Python code in HTML to be a good idea; it's too difficult to refactor, and PTL has various convenient features for automatically quoting HTML. > a forked process, and if so, is that too expensive? Do you know of > comparable packages for Python? One of the upsides of using Python is that many more non-Web-related packages have been written for it. Scientific programming is a significant application domain for Python, so several graphing packages have been written. You could use Reportlab for PDF generation, Chaco, Gnuplot, or Gist for graphing, or the Python Imaging Library for generating PNGs/JPGs. --amk |
|
|||
|
Here's how I see it (I'm a Web Developer by trade):
PHP - excellent database integration, if you don't want to have to use a Java application server for database work, go with PHP. Also nice templating system which even the Dreamweaver morons can work with. It is a bit slow at times (XML-RPC/SOAP implementations stink) and has limited data types. Python - excellent GUI support (PyQt/TKinter/wxPython are sooo easy), best suited to rapid application development - we use it for prototyping cross-platform C++ apps at work, also for wrapping GUI's around sysadmin scripts. Plus it's easy to distribute using distutils. Perl - bloody fast, if you're doing lots of text processing/regex (e.g. XML parsing) then Perl is it, probably best for sysadmin tasks too. We use this for large reports at work. I love its hash handling and wide range of modules. The moral of the story is don't get locked into one technology, use the best tools for the job - especially if you happen to know them all! ;o) |