473,394 Members | 1,726 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,394 software developers and data experts.

PHP vs. Python

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

Jul 18 '05 #1
22 2167
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/

Jul 18 '05 #2
st***********@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>

Jul 18 '05 #3
Hi !

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

Jul 18 '05 #4
On 22 Dec 2004 14:03:36 -0800, st***********@gmail.com
<st***********@gmail.com> wrote:
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.


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.
Jul 18 '05 #5
In article <11**********************@f14g2000cwb.googlegroups .com>,
st***********@gmail.com wrote:
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.


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
Jul 18 '05 #6
JZ
Dnia 22 Dec 2004 14:03:36 -0800, st***********@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
Jul 18 '05 #7
JZ <sp******@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.
Jul 18 '05 #8
huy
st***********@gmail.com wrote:
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


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
Jul 18 '05 #9
Paul Rubin wrote:
JZ <sp******@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.


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
Jul 18 '05 #10
On Wed, 22 Dec 2004 16:43:21 -0800, Paul Rubin wrote:
JZ <sp******@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.


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.
Jul 18 '05 #11
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.
Jul 18 '05 #12
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 dueto concerns about unknown security risks, and without that one carries theinterpreter 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 SQLqueries 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
:::::::::::::::::::::::::::::::::::

Jul 18 '05 #13
On Thu, 2004-12-23 at 06:03, st***********@gmail.com wrote:
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.


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

Jul 18 '05 #14
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>

Jul 18 '05 #15
JZ
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
Jul 18 '05 #16

"Eric Pederson" <wh****@now.com> wrote in message news:ma**************************************@pyth on.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
Jul 18 '05 #17
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

Jul 18 '05 #18
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

Jul 18 '05 #19

"Stephen" <st***********@gmail.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.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
Jul 18 '05 #20
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.
Jul 18 '05 #21
st***********@gmail.com wrote:
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


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).
Jul 18 '05 #22
JZ
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
Jul 18 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...

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.