Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PHP vs. Python

593 views
Skip to first unread message

stephe...@gmail.com

unread,
Dec 22, 2004, 5:03:36 PM12/22/04
to
Anyone know which is faster? I'm a PHP programmer but considering
getting into Python ... did searches on Google but didn't turn much up
on this.

Thanks!
Stephen

Marek Baczynski

unread,
Dec 22, 2004, 5:19:22 PM12/22/04
to
That depends what you consider faster. PHP will save you some q&d
hacking time, but Python will save you more in the longer term IMHO.
For the other speed, see http://shootout.alioth.debian.org/

Fredrik Lundh

unread,
Dec 22, 2004, 5:12:07 PM12/22/04
to pytho...@python.org
stephe...@gmail.com wrote:

> Anyone know which is faster? I'm a PHP programmer but considering
> getting into Python ...

faster for what? in my experience, people can hack into a PHP site in
no time at all, but maybe you meant something else?

(seriously, it depends on what you're doing, of course. and how you're
running your programs. and what kind of programs you're writing. and
what frameworks you're using. and, and. and, ...)

</F>

Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.

unread,
Dec 22, 2004, 6:03:39 PM12/22/04
to
Hi !

Relative in Python (and for local use), PHP is a tortoise with of a hand
brake.

Stephen Thorne

unread,
Dec 22, 2004, 6:55:33 PM12/22/04
to stephe...@gmail.com, pytho...@python.org
On 22 Dec 2004 14:03:36 -0800, stephe...@gmail.com

In terms of development, Python is a far better language to write code
in[1], has a much more mature standard library[2] and an excellent
community[3].

I've avoided your original question. Speed. Python is faster to
develop in, and is on-par with execution time. The trick is, with
python, you can trivially profile your application and re-write any
sections of code that are too slow in C, in pyrex, optimise them with
psyco, or just plain fix your efficiency problems.

Profiling in php isn't as easy as
import profile
profile.run("main()")

Regards,
Stephen Thorne.

[1] I have written php commerically for over 3 years. This isn't a
subjective look-from-afar. I actually know from down and dirty day-in
day-out experience.
[2] compare http://pear.php.net to "apt-cache search ^python"
[3] Look at http://bugs.php.net/ . There's something fundamentally
wrong with a language community where people who have stumbled on
honest-to-god bugs are abused.

Russell E. Owen

unread,
Dec 22, 2004, 6:59:35 PM12/22/04
to
In article <1103753016.7...@f14g2000cwb.googlegroups.com>,
stephe...@gmail.com wrote:

For web service, the first hurdle is picking which python web interface
to use, installing it and (if necessary) configuring your web server to
use it. (All that choice is great in many respects, but it does
complicate getting started.)

Anyway, once you've done that, i doubt you'll find any speed issues with
python, and it is a more pleasant language than PHP. (Unfortunately,
that initial hurdle can be a big one; I am still using PHP on my server
because I never cleared it.)

-- Russell

JZ

unread,
Dec 22, 2004, 7:33:21 PM12/22/04
to
Dnia 22 Dec 2004 14:03:36 -0800, stephe...@gmail.com napisał(a):

> Anyone know which is faster? I'm a PHP programmer but considering
> getting into Python ...

Python application servers (Webware, Skunkweb) can work much faster than
php. But it is true only for non-trivial code. Benchmark for "Hello world"
is a nonsense of course.

But pure speed is not the all. Python can scale better, has cleaner and
consistent syntax, better standard libraries and is a common language
rather than specific script language for web only.

--
JZ

Paul Rubin

unread,
Dec 22, 2004, 7:43:21 PM12/22/04
to
JZ <spam...@niet.com> writes:
> But pure speed is not the all. Python can scale better,

If a system is fast enough on a single processor, it doesn't need to scale.

huy

unread,
Dec 22, 2004, 8:25:29 PM12/22/04
to stephe...@gmail.com

Is PHP too slow for your needs ? Is that the reason for changing ? If it
is, then Python might not satisfy your need. If it isn't, have you
thought about why you want to use Python ? If you have, are there
greater benefits in total over PHP from what you understand of both PHP
and PYthon.

Not sure where you are currently at with your evaluation of Python so if
you could outline a few more points on your needs, wants, and
expectations it would help when answering your questions about Python.


Huy

Robert Kern

unread,
Dec 22, 2004, 8:57:07 PM12/22/04
to

I think he means, "scale to larger programs," not "scale to more
processors."

--
Robert Kern
rk...@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jeremy Bowers

unread,
Dec 22, 2004, 9:09:12 PM12/22/04
to

Your point is circular; "fast enough (right now)" can be defined as
"doesn't need to scale (right now)".

For any given server app, enough clients will bog it down. If you're
trying to claim that PHP has less trouble with this, I've seen a lot of
PHP sites go down under load, so it is clearly not a non-issue.

Python's scaling isn't automatic, it's just easier to do.

Paul Rubin

unread,
Dec 22, 2004, 9:27:14 PM12/22/04
to
Jeremy Bowers <je...@jerf.org> writes:
> Your point is circular; "fast enough (right now)" can be defined as
> "doesn't need to scale (right now)".
>
> For any given server app, enough clients will bog it down. If you're
> trying to claim that PHP has less trouble with this, I've seen a lot of
> PHP sites go down under load, so it is clearly not a non-issue.
>
> Python's scaling isn't automatic, it's just easier to do.

I've never heard of any large sites being done in Python, with or
without scaling. By a large site I mean one that regularly gets 100
hits/sec or more. There are many sites like that out there. Those
are the ones that need to be concerned about scaling.

For sites that get less traffic than that, they only reason they need
to scale if they're written in Python is that Python is too slow.

Eric Pederson

unread,
Dec 23, 2004, 1:19:24 AM12/23/04
to pytho...@python.org
Paul Rubin did say:

> For sites that get less traffic than that, they only reason they need
> to scale if they're written in Python is that Python is too slow.


Asked earnestly: is there a feel or quantification that Python is slower than PHP in network applications?

If, so, I am wondering if it is because of the traction PHP has in the web community leading to possibly tighter integration with (e.g.) Apache.

My beloved Python-oriented webhost doesn't currently support Mod-Python due to concerns about unknown security risks, and without that one carries the interpreter start-up burden for each invocation, as I understand it. Speed in a server-client environment does concern me a bit because 100+ hits per second would be the minimum realm of success for the web app I am building in Python (I do not foresee using PHP, so maybe I would convert everything to C++ if I had to, but I really would not want to have to...)

In everything I have done so far, Python's speed has been quite satisfactory, and I always remember the loud complainings in the MySQL forum about SQL queries that take seconds, minutes, days... only to end up magnitudes faster when someone points out the folly of the code or table set-up.

Not sure if the OP is considering Python v.s. PHP on the server or on the desktop (PHP isn't web only, except by common use); they are very different use cases.


Eric Pederson
http://www.songzilla.blogspot.com
:::::::::::::::::::::::::::::::::::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::::::::::::::::::::::::::::::::::

Craig Ringer

unread,
Dec 23, 2004, 2:02:43 AM12/23/04
to stephe...@gmail.com, Python list

Others have answered interpretations of your question other than
execution speed. I can't give you numbers on that - you'd probably have
to do some benchmarks yourself - but can offer a few suggestions.

First, Python can be _seriously_ fast for web use. You need to make sure
you're not starting and terminating interpreters all the time, so you'll
need to use a Python embedded web server proxied by Apache (like Zope
does), SCGI (as works well with Quixote), Twisted, or some other way of
running your code persistently. Persistent CGI usually means worrying
about memory leaks, but unless you're using flakey C extension modules
that shouldn't be a problem with Python.

If you have your Python code running as some sort of persistent server,
then you can use tools like Psyco to get a further (often very
impressive) speed boost. The biggest speed-up with Pysco that I've
clocked is 20x, but 3x - 5x is fairly common.

Whether it'll be faster or slower than PHP, I just can't guess. I think
it'd certainly be well worth a try, especially if you're writing any
more complex applications.

That said, for 90% of users development time matters more than execution
speed, and that's another matter entirely.

--
Craig Ringer

Fredrik Lundh

unread,
Dec 23, 2004, 2:40:03 AM12/23/04
to pytho...@python.org
Paul Rubin wrote:

>> But pure speed is not the all. Python can scale better,
>
> If a system is fast enough on a single processor, it doesn't need to scale.

the word "scale" doesn't necessarily imply performance. software developers
also deal with scales like program size, application complexity, team size, number
of external systems, etc.

</F>

JZ

unread,
Dec 23, 2004, 5:55:46 AM12/23/04
to
Dnia Wed, 22 Dec 2004 20:57:07 -0500, Robert Kern napisał(a):

> I think he means, "scale to larger programs," not "scale to more
> processors."

Yes. I will try to be more specific. There is several reasons why Python
scales better than PHP.

(1) Python uses namespaces, PHP - not. The bigger programm the bigger
probability of conflict among names in PHP.

(2) Not only PHP lacks namespaces. It has one big inconsistent mess with
its function naming! Inconsistent prefixes, order of parameters. Mess. It
is difficult to memorize it. Python programming need less interupting for
reading manual.

(3) Python uses modules, PHP - not. Python can download single or some
classes from many big modules (eg. from module1 import class1, var1, fun1).
PHP is primitive in its copy-paste *all* included files! So Python uses
less memory than PHP and do not need to parse so many lines.

(4) Python automatic compile every imported modules into bytecode, PHP has
to parse all those mess. Without accelerators PHP is much slower for bigger
applications. This is the reason why PEAR is so slow. This is the reason
why ezPublish is so slow. The bigger code (more included files), the slower
PHP works.

(5) Python compile its modules automatic and do not need to parse them for
every browser request like PHP do.

(6) Pythonic application server (eg. Webware) do not need to load and parse
any files from filesystem at all! It loads them once, compile it and store
compiled scripts in memory. PHP has to load files from filesystem, parse
them and execute. From my own experience: when I moved from PHP to Webware
and I compared its performance with (similar scale) php appplications, my
webware was almost 6 times faster!

(7) Python has much better free IDE editors with graphic debugger inside.
PythonWin, Boa, SPE, Eric3 etc. It is much easier debug in Python than i
PHP for larger programmes.

(8) And last but not least. Python is truly object oriented, general
purpose language. PHP is not general purpose language. PHP4 has very poor
OO. (PHP5 has better, but has also some useless new features like private
variables. They have sense for static compiled languages like C++ or Java ,
not for dynamic ones.) Python also uses sofisticated exception handling,
uses namespaces, has module import, has better unicode support, has more
consistent api etc.
One more example from my experience. I always have problem with converting
string among iso-8859-2, cp1250, mac-ce and utf-8. PHP utf8 functions are
poor, implements useless (for me) iso-8859-1 only. iconv library for PHP is
even worse, when it cannot convert some characters it deletes the following
characters! PHP has no such like: unicode(txt, 'cp1250').encode('cp1250',
'xmlcharrefreplace'). When some characters exists only in cp1250 but not in
iso-8859-2 that function convert them into xml entity &#number; Cute!

--
JZ ICQ:6712522
http://zabiello.com

Roger Binns

unread,
Dec 23, 2004, 11:23:32 AM12/23/04
to

"Eric Pederson" <whe...@now.com> wrote in message news:mailman.8301.1103782...@python.org...

> My beloved Python-oriented webhost doesn't currently support Mod-Python

You can always do what I did. I wrote the backend of my app in Python
and run it as an XML-RPC server. I did the front end in PHP using the
Smarty template tool. (The actual templates themselves were stored
in the Python server and grabbed via XML-RPC). Effectively PHP/Smarty
were formatting XML-RPC results, delivered as Python dicts which turn
into Smarty arrays (and it all works fine with nested lists and dicts).

That way I got the best of both worlds, didn't have to get mod-python
installed, and *my opinion* is that Smarty is the nicest template tool
I have tried in Python or PHP.

Roger


Jeff Shannon

unread,
Dec 23, 2004, 1:26:28 PM12/23/04
to
JZ wrote:

>(3) Python uses modules, PHP - not. Python can download single or some
>classes from many big modules (eg. from module1 import class1, var1, fun1).
>PHP is primitive in its copy-paste *all* included files! So Python uses
>less memory than PHP and do not need to parse so many lines.
>
>

Not that I'm disagreeing with your overall premise here, that Python
scales better, but this particular point appears to contain (or at least
encourage) some misconceptions.

Yes, Python can import only one or two functions/classes from a large
module. But in order to do that, the entire module must be imported and
loaded into sys.modules, and then individual elements of that module are
bound to names in the current namespace. You're not actually saving any
memory or parsing time by only importing a few names, because

from module1 import class1

hass effectively the same end result as

import module1
class1 = module1.class1
del module1

(except that the former is a few less changes in the current
namespace). The performance advantages of importing only one or two
names are quite minimal; the only real reason to do it is to save typing
and to have code that might be seen as 'cleaner' (though the latter is a
debatable point, depending on specific circumstances).

Jeff Shannon
Technician/Programmer
Credit International

Stephen

unread,
Dec 23, 2004, 6:10:40 PM12/23/04
to
I like the idea of being able to port specific sections to C ... Python
seems more flexible than PHP ... scalable.

We're mainly using it to drive dynamic web apps ... online store ...
etc.

Thanks Again!
Stephen

Roger Binns

unread,
Dec 23, 2004, 7:08:10 PM12/23/04
to

"Stephen" <stephe...@gmail.com> wrote in message news:1103843440.3...@f14g2000cwb.googlegroups.com...

>I like the idea of being able to port specific sections to C ... Python
> seems more flexible than PHP ... scalable.

If you want portions of your code in C, then wrap them with Swig.
That way they can be available in any number of languages including
Python, PHP, Java and Perl.

http://www.swig.org/compare.html

Roger


Duncan Booth

unread,
Dec 24, 2004, 6:15:46 AM12/24/04
to
Paul Rubin wrote:

> I've never heard of any large sites being done in Python, with or
> without scaling. By a large site I mean one that regularly gets 100
> hits/sec or more. There are many sites like that out there. Those
> are the ones that need to be concerned about scaling.

How exactly would you know which large sites are using Python? The PHP
sites tend to advertise their use of PHP by file extensions on every URL,
but a lot of Python sites don't.

I don't know how to tell how many hits a random site has, but there are
certainly some big users out there. For example Viacom uses Zope for many
of its CBS and UPN websites. LastMinute.com, who definitely hit your large
site definition, were working with Zope as well although so far as I know
nothing has yet reached their live site.

Jon Perez

unread,
Dec 27, 2004, 1:54:13 PM12/27/04
to

If you're talking about usage as a server side scripting
language, then PHP will likely give better page serving
throughput for the same hardware configuration versus
even something that is mod_python based (but I believe
the speed diff would be well under 100%).

However, Python is just so much superior as a language (I
was deep into PHP before I tried out Python and I always hate
having to go back to PHP nowadays in the cases where it is
unavoidable) that you will still want to use Python even if
PHP requires lower server specs to handle the same throughput.

Also, if you have a more complex application for which
pooled variable reuse is an important performance-determining
factor, Python-based server-side scripting solutions might
offer better control of this aspect and may thus yield
superior performance to a PHP-based one.

The real problem with Python is not speed but _availability_.
The number of hosting services out there supporting mod_php
completely outstrips those supporting mod_python. Moreover, they
are significantly cheaper, and offer a lot more features
(Fantastico, etc...). The python-based hosting solutions
out there tend to be dedicated to Python and thus do not
offer these solutions.

If this is not an issue (i.e. you will be running your
own server), then I highly recommend going the Python
route using something like Spyce (which is the closest
thing to PHP in the Python world).

JZ

unread,
Dec 27, 2004, 5:24:28 PM12/27/04
to
Dnia Tue, 28 Dec 2004 02:54:13 +0800, Jon Perez napisał(a):

> If you're talking about usage as a server side scripting
> language, then PHP will likely give better page serving
> throughput for the same hardware configuration versus
> even something that is mod_python based (but I believe
> the speed diff would be well under 100%).

I have different experience. When I moved from PHP to Webware


and I compared its performance with (similar scale) php appplications,

my webware was almost 6 times faster! Application servers are always
faster because they use compiled scripts stored in memory. They do not need
to load files from filesystem nor parse them. PHP is faster only for
trivial, useless benchmarks like "Hello world". For bigger code Python is
faster than PHP.

> The real problem with Python is not speed but _availability_.

You have rigth here.

--
JZ

tejas.t...@gmail.com

unread,
Sep 25, 2012, 12:57:56 AM9/25/12
to

andrea crotti

unread,
Sep 25, 2012, 6:01:58 AM9/25/12
to tejas.t...@gmail.com, pytho...@python.org
2012/9/25 <tejas.t...@gmail.com>:
> --
> http://mail.python.org/mailman/listinfo/python-list


Quite ancient versions of everything, would be interesting to see if
things are different now..

Anyway you can switch to Python happily, it might not be faster but
99% of the times that's not an issue..

Mark Lawrence

unread,
Sep 25, 2012, 6:41:22 AM9/25/12
to pytho...@python.org
On 25/09/2012 11:22, Tejas wrote:
> How to configure python in apache2 ?
>
> So my html embedded code will works.
>
>
>

Please follow the instructions that you'll find by searching the web.

--
Cheers.

Mark Lawrence.

0 new messages