PHP vs. Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JZ

    #16
    Re: PHP vs. Python

    Dnia Wed, 22 Dec 2004 20:57:07 -0500, Robert Kern napisa³(a):
    [color=blue]
    > I think he means, "scale to larger programs," not "scale to more
    > processors."[/color]

    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').encod e('cp1250',
    'xmlcharrefrepl ace'). 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

    Comment

    • Roger Binns

      #17
      Re: PHP vs. Python


      "Eric Pederson" <whereU@now.com > wrote in message news:mailman.83 01.1103782761.5 135.python-list@python.org ...[color=blue]
      > My beloved Python-oriented webhost doesn't currently support Mod-Python[/color]

      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


      Comment

      • Jeff Shannon

        #18
        Re: PHP vs. Python

        JZ wrote:
        [color=blue]
        >(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.
        >
        >[/color]

        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

        Comment

        • Stephen

          #19
          Re: PHP vs. Python

          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

          Comment

          • Roger Binns

            #20
            Re: PHP vs. Python


            "Stephen" <stephen.mayer@ gmail.com> wrote in message news:1103843440 .322825.320840@ f14g2000cwb.goo glegroups.com.. .[color=blue]
            >I like the idea of being able to port specific sections to C ... Python
            > seems more flexible than PHP ... scalable.[/color]

            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.



            Roger


            Comment

            • Duncan Booth

              #21
              Re: PHP vs. Python

              Paul Rubin wrote:
              [color=blue]
              > 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.[/color]

              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.

              Comment

              • Jon Perez

                #22
                Re: PHP vs. Python (speed-wise comparison)

                stephen.mayer@g mail.com wrote:[color=blue]
                > 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[/color]

                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).

                Comment

                • JZ

                  #23
                  Re: PHP vs. Python (speed-wise comparison)

                  Dnia Tue, 28 Dec 2004 02:54:13 +0800, Jon Perez napisa³(a):
                  [color=blue]
                  > 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%).[/color]

                  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.
                  [color=blue]
                  > The real problem with Python is not speed but _availability_.[/color]

                  You have rigth here.

                  --
                  JZ

                  Comment

                  Working...