PHP vs. Python

Discussion in 'Python' started by stephen.mayer@gmail.com, Dec 22, 2004.

  1. Guest

    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
     
    , Dec 22, 2004
    #1
    1. Advertising

  2. 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>
     
    Fredrik Lundh, Dec 22, 2004
    #2
    1. Advertising

  3. 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/
     
    Marek Baczynski, Dec 22, 2004
    #3
  4. Hi !

    Relative in Python (and for local use), PHP is a tortoise with of a hand
    brake.
     
    Michel Claveau - abstraction méta-galactique non t, Dec 22, 2004
    #4
  5. On 22 Dec 2004 14:03:36 -0800,
    <> 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.
     
    Stephen Thorne, Dec 22, 2004
    #5
  6. In article <>,
    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
     
    Russell E. Owen, Dec 22, 2004
    #6
  7. JZ Guest

    Dnia 22 Dec 2004 14:03:36 -0800, 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
     
    JZ, Dec 23, 2004
    #7
  8. Paul Rubin Guest

    JZ <> 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.
     
    Paul Rubin, Dec 23, 2004
    #8
  9. huy Guest

    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
     
    huy, Dec 23, 2004
    #9
  10. Robert Kern Guest

    Paul Rubin wrote:
    > JZ <> 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


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
     
    Robert Kern, Dec 23, 2004
    #10
  11. On Wed, 22 Dec 2004 16:43:21 -0800, Paul Rubin wrote:

    > JZ <> 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.
     
    Jeremy Bowers, Dec 23, 2004
    #11
  12. Paul Rubin Guest

    Jeremy Bowers <> 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.
     
    Paul Rubin, Dec 23, 2004
    #12
  13. 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
    :::::::::::::::::::::::::::::::::::
     
    Eric Pederson, Dec 23, 2004
    #13
  14. Craig Ringer Guest

    On Thu, 2004-12-23 at 06:03, 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
     
    Craig Ringer, Dec 23, 2004
    #14
  15. 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>
     
    Fredrik Lundh, Dec 23, 2004
    #15
  16. JZ Guest

    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 Cute!

    --
    JZ ICQ:6712522
    http://zabiello.com
     
    JZ, Dec 23, 2004
    #16
  17. Roger Binns Guest

    "Eric Pederson" <> wrote in message news:...
    > 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
     
    Roger Binns, Dec 23, 2004
    #17
  18. Jeff Shannon Guest

    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
     
    Jeff Shannon, Dec 23, 2004
    #18
  19. Stephen Guest

    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
     
    Stephen, Dec 23, 2004
    #19
  20. Roger Binns Guest

    "Stephen" <> wrote in message news:...
    >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
     
    Roger Binns, Dec 24, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Zeng
    Replies:
    4
    Views:
    572
    Tim Arnold
    Oct 3, 2006
  2. Ted Zeng
    Replies:
    0
    Views:
    686
    Ted Zeng
    Oct 13, 2006
  3. torque63
    Replies:
    0
    Views:
    666
    torque63
    Jan 1, 2009
  4. raviraj joshi
    Replies:
    0
    Views:
    360
    raviraj joshi
    Jul 4, 2009
  5. Rajive Narain
    Replies:
    0
    Views:
    2,091
    Rajive Narain
    Sep 18, 2009
Loading...

Share This Page