View Full Version : PHP vs Perl
Chosen
01-17-2001, 01:17 PM
Can anyone tell me how faster actually PHP than Perl? And is there difference in speed between PHP3 & PHP4 ?
Thanks http://bbs.adultwebmasterinfo.com/ubb/smile.gif
Mogul
01-17-2001, 01:21 PM
There really is no stright answer on what is faster as it depends on what you are doing.
PHP is better if that helps ;-) With all the web programming we do, we use perl only on backend stuff it at all.
PHP4 is re-written by Zend and is close to compatibility with PHP3. PHP4 has a few other enhancements like session variables. Also Zend put out a optimization enhancement to speed up php4 even further.
Check out zend.com for more info. Use PHP4 if you can.
Hope that helps some.
A friend of mine did a test and according to the test PHP was almost 4 times faster than perl.
PHP3 vs PHP4 no idea.
Muff
TheAce
01-17-2001, 02:29 PM
If you have the need for speed IE: If you expect thousands of calls per hour then you need to write CGI in c++ NOTHING ELSE.
Chosen
01-17-2001, 03:01 PM
I know some PHP, but it would take a lot of time for me to learn C++. Anyway if someone compared scripts in C++ with similar ones written in PHP or Perl, please post results here
neocorp
01-17-2001, 03:06 PM
There are more more and toplists written in php, the big advantage, is that they are pretty difficult to cheat thanks to unique sessions, and they are pretty fast, but maybe it takes some server space, no ?
richard
01-18-2001, 03:25 AM
lots of php scripts are about beacuse its easy to code in.
C if obviously going to be faster - php is a hyper text pre processor (? something like that) written in C, hence a hard coded C script would be faster... if coded well...
I am playing around with mod_perl for some high performance stuff, again its a built in interpreter which is compiled into Apache, written in C, but because i know perl, i can code alot faster than if i tried learning C.
How far do you go though? a script written in ASM would be super douper fast, but would take aaaaagges to code, and unless you are some ASM god, might be more poorly coded ASM than C creates....
Anyone fancy coding a CJ script in pure binary?
nope, didn't think so http://bbs.adultwebmasterinfo.com/ubb/smile.gif
IŽd recommend: Learn php yourself for doing some special stuff, itŽs fun. But youŽll still need to use perl here and there whenever youŽd like to use some ready to go scripts since there arenŽt many available in php but there are lots in perl.
For do-it yourself i find php to be much more comfortable because you simly write the code into the html pages wihtout the chmod crap.
C++ could of course smoke both of them in terms of performance.
Jimbo
01-19-2001, 03:27 PM
yeah PHP is a peace of cake to learn and much faster than perl! but Mod_perl whoops PHP ass I think (no test done) the problem is that you need to be almost alone on a server to use it since it all loads in memory (modules)
Jimbo
btw I'm looking for some persons who have used mysql_pconnect() without any problems (mine seems to not use the opened connection like it should do http://bbs.adultwebmasterinfo.com/ubb/frown.gif so it just opens bunch of connections until MySQL crashes http://bbs.adultwebmasterinfo.com/ubb/biggrin.gif
Jimbo
Basically a script written in C is faster than almost anything else if you know what you do. And C isn't as difficult to learn or use as many think. Actually, it's quite easy and logic. However writing a CGI script in C can be a load of a mess since debugging it needs a lot of time (uploading a new version, compiling it, testing it)... and the fact that it doesn't print out errors in the error_log file by default doesn't help either. But once you're into it it's a lot easier than Perl or PHP in my opinion. I personally hate writing scripts in Perl since it's awfully hard to read perl code. Perl also has a serious speed problem and mod_perl does make it faster BUT Jimbo is right, you need a lot of memory in order to use all of its advantages since it loads each and every script using mod_perl to the shared memory... and believe me perl doesn't compile its scripts to be memory efficient.
PHP is nice and it's easier to use and generally faster than perl but it doesn't reach C's performance anywhere. However using persistent connections in PHP is no good idea. This crashes your server in no time.
Think of this: A typical webserver (apache) has about 200 children all of which can have 1 persistent connection, all of which then need one mysql instance which need a lot of memory. I think you can imagine the mess this will cause.
Btw don't mix up C++ and C! C++ is an extension of C but it's not C, even though C is part of C++.
TheAce
01-19-2001, 07:50 PM
The reason PHP and Perl are not really worth a damn on a high traffic site is because they use a interpreter instead of a complier.
Pretty much a interpeter just reads the instructions as it needs them.
A compiler, however makes the translation once, then saves the machine language so that thae instructions do not have to be translasted each time.
So when ever you need to chose a language to write a program in and you expect lots and lots of load on it, then write it with a programming language that uses a compiler not a interpeter.
However when you need to do something that you don't expect a heavy load then you may write it in a language that uses a interpeter cause they are usually a very high level programming language and will save ya time.
------------------------------------------
You don't have to upload C++ scripts to test them...... lol just buy microsoft c++ like most programmers do.
Perl script are actually compiled. Where you lose time is on the startup, but there is this wonderful thing called embedded perl - the script is compiled and the interpreter is stated only once - when then the webserver starts.
aquitaine
01-19-2001, 09:48 PM
hmm , after all the hardline talk about C I still have to say that mod_perl does better than a c binary does since mod_perl allows the script to run in the same space.
Yeah it does need more memory, but i dont see that as much of a problem any more. Hardware harldy costs !
I was reading up about the benchmark of a certain script, not saying i advocate it , but from the results these people have, i would say mod_perl is better.
http://cgi-works.net/scripts/autorankpro/bench.html
check that page out.
The difference in perl and c is that , you may be able to write faster code in c, but you can allways write code faster in perl http://bbs.adultwebmasterinfo.com/ubb/smile.gif
Just my 20 dollars http://bbs.adultwebmasterinfo.com/ubb/smile.gif
<font face="Verdana, Arial" size="2">Originally posted by TheAce:
You don't have to upload C++ scripts to test them...... lol just buy microsoft c++ like most programmers do.
</font>
I must disappoint you http://bbs.adultwebmasterinfo.com/ubb/smile.gif Since most CGI scripts need some libraries, unless you want to invent the wheel yourself everytime you write a script, which can NOT be compiled in WIN32 because they've code customised for use on Unix.
richard
01-20-2001, 03:52 AM
Perl's problem is the overhead of starting up a new perl.exe everytime a cgi file is called. Surely Gernot, if a script is called once per second, you will have perl.exe loaded into memory (about 5meg) then compile the script, and exit.
With mod_perl, the script is compiled once (at startup or the first time it is called), then cached in the memory to be use for subsequent requests.
Tell me how that uses more memory than having each script compiled each time it is requested, please! http://bbs.adultwebmasterinfo.com/ubb/smile.gif
i agree with the statement that mod_perl is a complete bitch unless you have your own box.
But hey, i have my own box http://bbs.adultwebmasterinfo.com/ubb/biggrin.gif
http://bbs.adultwebmasterinfo.com/ubb/wink.gif Gernot, using a frontend/backend setup (which is becoming the norm) with mod_perl can eleviate memory problems a great deal.
I.E. One very lightweight version of apache to deal with images / static html files etc, and one compiled with mod_perl.
Those who do play with apache, check out a PHP4 enabled httpd - now that is a big mumma compared to a mod_perl httpd.
This setup also means that a mod_perl server with persistant connections to a MySQL server does not have lots of mysqlds hanging around.
Every situation, for every script, is different though.
richard
01-20-2001, 04:04 AM
interesting benchmarks there aquitaine.
However, it does show that for the highest traffic, the C version was kicking some ass.
It shows i guess, how different languages have their own benefits / disadvantages.
My interpretation of those results is that the mod_perl server is the fastest at responding to the incoming request. This is because the script is built into apache (i assume, rather than using apache::registry?) basically making it a part of apache.
However, as the # of ip addresses increases, C comes into its own with its file IO i would imagine, and its searching of the data in the files.
Interesting stuff this.
Rich, mod_perl definitly is excellent if there're only few scripts using mod_perl on a box. So you can run a good CJ script using mod_perl as there're only 2 scripts that need to be loaded in the memory (in and out). It does kick perl's ass there... no doubt. It also kicks C's ass in this case, as the benchmark shows since the mod_perl script doesn't need to be loaded in the memory at every run whilst the C script has (although it is compiled, it still needs to be loaded into memory at every run which takes some time).
Mod_perl is nearly as good as a C script but it doesn't reach its performance at really heavy usage since it's not optimized (yet). I can imagine that the creators of mod_perl are going to optimize that to improve its speed even more but they can't change anything on the fact that mod_perl is no good solution for people who need a bunch of scripts running using mod_perl since they would need too much memory.
For people who don't have their own box a well written C script is by far the best solution as it has the best IO engine. The bad thing about that is that most programmers who write scripts in C don't know how to optimize the IO operations.
So my suggestion http://bbs.adultwebmasterinfo.com/ubb/smile.gif
On
- Virtual Servers : C then PHP
- Dedicated Servers: C closely followed by mod_perl
richard
01-20-2001, 05:00 AM
fair enough http://bbs.adultwebmasterinfo.com/ubb/biggrin.gif
though i think your memory point is a little rocky.
sure, if the server has 100 different scripts, and they are called infrequently, say a couple of times each, then it would be a waste to load them into memory.
However, in that case run all scripts that are used often under mod_perl, and run less used ones under normal mod_cgi.
But yea, i agree C is the bomb, but every situation warrants a different solution.
Filipe
01-20-2001, 05:20 AM
I hope one day I will be able to discuss this chinese talk with you too http://bbs.adultwebmasterinfo.com/ubb/biggrin.gif
I fully agree http://bbs.adultwebmasterinfo.com/ubb/smile.gif
richard
01-20-2001, 05:32 AM
lol Filipe.
Avatar
01-20-2001, 06:07 AM
Can anybody recommend a good resource of php and c++ programming?
I know c++, but just not how to glue it together with html.
Jimbo
01-20-2001, 03:03 PM
for php I recommend the PHP manual (in multiple languages http://bbs.adultwebmasterinfo.com/ubb/smile.gif ) at www.php.net (http://www.php.net)
as for C++ I can't help here, I just use my school books for that http://bbs.adultwebmasterinfo.com/ubb/biggrin.gif
Jimbo
<font face="Verdana, Arial" size="2">Originally posted by Avatar:
Can anybody recommend a good resource of php and c++ programming?
I know c++, but just not how to glue it together with html.</font>
The same way as you glue it in perl - print to stdout and read from the environment variables.
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.