PHP vs Python

Alain TESIO alain at onesite.org
Mon Jan 15 16:09:34 EST 2001


On Mon, 15 Jan 2001 01:42:34 GMT, "TC" <trclark at home.com> wrote:

>Hi
>I did a quick search for deja python +php +review
>not even 1 relevent hit ...so
>any takers points of interest
>
>0- how long is a peice of string ? ;)

n bytes where n is the number of characters in the string,
(2n bytes if it is an Unicode string)

>1-which one is going to be around longer, why ??
>
>
>2-who has more users

from altavista :

python AND (mod_snake OR NOT snake) => 186,508 pages
php => 177,182 pages (overestimated as it's the default extension)

>3-who hits the wall in scaling up and or handing complexity

Google didn't choose python

for feature in features:
   sucks=php.has_key(feature)
   rules=python.has_key(feature)
   if sucks and not(rules):
      if not ( feature in [ curly_braces , tags_everywhere , semicolons ] ) :
          raise SystemError
   if not(sucks) and rules:
      print feature

gives back :

exceptions
modules
great newsgroup with helpful people

>4-general performance

The killer benchmark :


eris:~/www/cgi-bin$ cat > sucks.php
<?php
for (;;)
{
    if (mt_rand(0,1000000)==1)
        die("Got it !\n");
}
?>

eris:~/www/cgi-bin$ time ./php < sucks.php
X-Powered-By: PHP/4.0.2
Content-type: text/html

Got it !
4.60user 14.27system 0:21.73elapsed 86%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (364major+110minor)pagefaults 0swaps

eris:~/www/cgi-bin$cat > rulez.py
import random
while random.randint(0,1000000)!=1000000:
    pass
print "Got it !"

eris:~/www/cgi-bin$ time python rulez.py 
Got it !
0.00user 4.32system 0:05.44elapsed 79%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (230major+94minor)pagefaults 0swaps


I have no idea why php uses user time whereas python doesn't, a good point is that a
newbie sysadmin will believe that you aren't using much of the cpu with python as user is
0.

>5-where would I be better off using PHP over Python

PHP is you need a web counter, Python for anything larger or if you need your counter to
be skinable.

>6-DB interfaces consistent
>   -seems python has a standad API PHP appears all over the map depending on
>DB

<serious>

Similar APIs (their efficiency being the one of the language itself)

Personal experience : I use php for my site onesite.org, unfortunately I didn't know
python at this time, and now I'm forced to rewrite everything.

Python is a general purpose language, php is just meant to be embedded in web
pages. If you need something like me (as a mail robot, cron jobs, ...), two choices :

1. use python and be consistent, share code
2. use php on the web, and for non-web code :
   2.1  shellscripts (remove this option and come back here one month later)
   2.2  use perl (remove this option and come back here when you're tired with @;{}%#
   2.3  use python (and rewrite the web code in python ...)


Alain




More information about the Python-list mailing list