Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Sterling Hughes

On Sun, 16 Sep 2001, Bora Paksoy wrote:

 Hi;

 I am planning to implement a new site which will be
 using mysql db heavily, and I am in the middle of (and
 stuck:) deciding what I should use for implementation.
 I would definitely prefer Java Servlets, but it is
 very expensive to host servlets, so I am only
 comparing PHP vs. Perl.


Why on earth would you prefer java servlets?

 I have been hearing very good things about PHP for a
 long time, and I started reading the manual/tutorial
 posted on php.net. To be honest, I didn't see much
 difference from perl. It is almost identical (I have
 to admit, there are some practical advantages, but not
 a huge difference), even the syntax is almost same to
 perl.


PHP is a much cleaner language than Perl, ie, it doesn't have the
same abiguities that plague Perl (print reverse split
/\s+/, H P A J;) and is much more akin to C in many ways.  Also,
PHP was written and intended for the web (it can be used in other
veins as well), therefore its imho much easier to do web programming
with php.

 Comparing basic functional stuff:

 1.Speed: If you use mod_perl or fastcgi kind of deals
 (which are based on threadding instead of forking), I
 don't think PHP is considerably faster than perl? Is
 that the case?

The speed is comparable between the two languages, but then again if
you count all the extra Perl libraries you have to call in to
achieve the same results, php starts to win.

FYI, JSP is the slowest to my knowledge.

 2.Database Connection: What is the BIG advantage of
 PHP here? Using DBI packages for perl, and fastcgi for
 db connection pooling, you can achieve the same thing,
 I guess. It just looks like PHP has some of these
 libraries embedded in the core language, but the idea
 is same--implementing the native db protocol over
 sockets?


The PHP way is slightly faster, that's it though (yeah, yeah, I know
database independence, but if you want your code to run with any
speed you'll tune your sql for the individual database anyway,
loosing the necessary portability).

 3.Shared Memory, global variables, etc: I was
 expecting a better interface for this in PHP, and I
 was really disappointed to see that developers have to
 use O/S level shared memory. First of all, this is not
 available on Windows And, it is kind of messy and
 hard to use, especially when you compare this to
 Java's static variables.


No, its not available on Windows, but then again, why on earth would
you want to use Windows? ;) If you really need shm on windows,
submit a patch, hint, its just a mmap() :)

The same applies for perl btw...  I have a feeling your not talking
about Shared memory by the way, but rather sessions, which you can
do via the built-in PHP sessioning support, see below.  Shared
memory is usually only a good idea (outside of the session scope)
when you want to communicate with other programs/processes.  Using
it on high traffic sites is also not a good idea.

 4.Session Management: If you use files to manage
 sessions, same thing can be achieved in perl.
 Regarding in memory session management, as far as I
 know, FastCGI can share variables among sessions, so
 it shouldn't be hard to write a session manager in
 perl as well.


You can use Files or SHM management, or write your own custom
session backend using for example MySQL.

 5.Architecture: I couldn't find any doc about how PHP
 works. And any answer to important questions, like
   -How does compilation process work? Does the PHP
 engine compile htmls first time a request is made to
 that html and use that compiled code later on(just
 like JSPs), or does it compile everytime? Is PHP
 engine an interpreter, jvm-like byte-code
 generator/executer or a compiler?

No.  Its compile and execute everytime, however if you use one of
the Cache's mentioned below its simply an execute each time.  JSP
btw is slower despite the fact that it compiles the stuff ahead of
time.

   -How does threadding work? How can you cache stuff,
 etc.?

you can cache your scripts using the commercial (but higher quality) Zend Cache
(www.zend.com) or the (free) APC Cache (apc.communityconnect.com).

   -What is the generic lifecycle of a request/response?


zend.com should have some information on this.

 6. Embedding scripts in HTML: Well, I mean, this is
 similar to JSP, but what the hell, you can use AA
 . AA; syntax and embed any string you want at any
 point by mixing and matching HTML and perl code. I
 mean, yeah PHP is easier, but it is not considerably
 easier, I believe.


Yes, but do you want your web designer going through your perl code
and messing with that section alone?  Its much easier to maintain
the PHP code in this respect (you could use a templating engine in
Perl of course, but that would slow your code down another notch).
Also, with Perl HERE blocks 

Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Rasmus Lerdorf

 1.Speed: If you use mod_perl or fastcgi kind of deals
 (which are based on threadding instead of forking), I
 don't think PHP is considerably faster than perl? Is
 that the case?

Threading instead of forking?  None of these do either.  Apache is a
pre-forking multi-process server and both PHP and mod_perl are part of
these pre-forked processes.  Neither mod_perl nor PHP do any threading nor
forking.

 2.Database Connection: What is the BIG advantage of
 PHP here? Using DBI packages for perl, and fastcgi for
 db connection pooling, you can achieve the same thing,
 I guess. It just looks like PHP has some of these
 libraries embedded in the core language, but the idea
 is same--implementing the native db protocol over
 sockets?

No difference.

 3.Shared Memory, global variables, etc: I was
 expecting a better interface for this in PHP, and I
 was really disappointed to see that developers have to
 use O/S level shared memory. First of all, this is not
 available on Windows And, it is kind of messy and
 hard to use, especially when you compare this to
 Java's static variables.

Again, the architectural difference makes this a lot easier to do in a
single-process JVM scenario.  Note that such a single-process JVM
architecture which maintains static objects is very hard to scale cleanly.

 4.Session Management: If you use files to manage
 sessions, same thing can be achieved in perl.
 Regarding in memory session management, as far as I
 know, FastCGI can share variables among sessions, so
 it shouldn't be hard to write a session manager in
 perl as well.

Probably true.

 5.Architecture: I couldn't find any doc about how PHP
 works. And any answer to important questions, like
   -How does compilation process work? Does the PHP
 engine compile htmls first time a request is made to
 that html and use that compiled code later on(just
 like JSPs), or does it compile everytime? Is PHP
 engine an interpreter, jvm-like byte-code
 generator/executer or a compiler?
   -How does threadding work? How can you cache stuff,
 etc.?
   -What is the generic lifecycle of a request/response?

PHP is a 2-stage interpreted language.  First pass generates opcodes,
second pass executes the opcodes.  Various add-on caches and optimizers
can cache the opcodes and thus skip the interpreter step.  Doesn't usually
win you a whole lot unless you have quite complex logic in your pages
though.  The interpreter is pretty fast.

There is no threading in PHP.  The web server provides the base
thread/process architecture.

The lifecycle of a request/response matches the lifecycle of an HTTP
request/response.

 6. Embedding scripts in HTML: Well, I mean, this is
 similar to JSP, but what the hell, you can use AA
 . AA; syntax and embed any string you want at any
 point by mixing and matching HTML and perl code. I
 mean, yeah PHP is easier, but it is not considerably
 easier, I believe.

Probably not.

 I have been searching the internet to find some
 serious comparisons, but all I found was a stupid page
 which compares the syntax rather than functionality.

 As I said, I really need to start developing soon, and
 I would appreciate comments regarding this issue.

Basically any language can be used to write web apps.  There is nothing in
PHP you can't do in Perl, ASP, Cold Fusion, Python or JSP.  PHP just
happens to package things together in a easy to comprehend way and
everything you read about PHP is geared towards the Web problem whereas in
the case of more general-purpose scripting languages it can be confusing
trying to figure out how to approach the web problem.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Bora Paksoy

 Why on earth would you prefer java servlets?

Hmm... Let's see;Java is a full-fledge, totally OOP
and awesome programming language but not a scripting
language. Speed (will be mentioning this later),
having total control over whatever you want (exception
handling, db pooling, caching, syncrhonization,
threadding, etc. etc.), ease of use, etc. etc. I mean,
come on;)

 veins as well), therefore its imho much easier
 to do web programming with php.

That is what I saw, but as I said, I didn't see a lot
of difference between perl and php, I mean, C++ and
perl are very different, likewise java and perl or
other languages, but PHP has a very similar syntax.

 FYI, JSP is the slowest to my knowledge.

The first request is slow since JSPs are compiled into
servlets (java classes)... But, then it is not bad...
In fact, I saw some comparisons showing that servlets
are kicking ass! But, again, I mean, this all depends
on how you design/configure the system, one simple
example:java used to crap out (before 1.2, don't know
the latest situation, but heard that it is better)
after 40-50 threads per jvm, so if  you have more than
40-50 concurrent requests, starting couple of servlet
engines on different jvms and using apache dispatching
improves the speed a lot! Likewise, tricks like using
caching, staying away from classic traps (i.e. using
StringBuffers instead of Strings when needed),
minimizing garbage collection, etc. etc. Also, with
the introduction of JIT and hotspot capable JREs, java
is doing pretty well these days...You can check
comparisons at rasin servlet engine page.

 No, its not available on Windows, but then
 again, why on earth would you want to use Windows?
;) 

Same here;) I am supposed to implement this sytem on
windows 2000...But I totally agree! I would definitely
prefer linux or other unix systems over windows...

If you really need
 shm on windows, submit a patch, hint, its just a
mmap() :)

Well, what I meant was something like ease of sharing
data in java (using static variables) and dealing with
synchronization is extremely easy in java... Also,
FastCGI is not that hard as far as I could see, but I
am not an expert in that area;)

 You can use Files or SHM management, or write
 your own custom session backend using for example
MySQL.

Using a database in the backhand is what huge sites
are doing, but they have huge boxes to run these
databases and very fast network infrastructure. Do you
think overhead of serializing/de-serializing session
for every request via the database is a lot? Files
again is??? I don't know... As you specified SHM is
not very nice either (dealing with synchronization
might be messy).

 No.  Its compile and execute everytime

??? Don't you think using perl and printing out html
from the code is faster than this? I mean, parsing the
whole html doesn't seem very good???Actually, this is
what I was scared of. I mean, for example say you have
an html that consists of blocks... Making every block
an include is clean, but this time, php engine has to
read all of these includes, and parse the html+php and
compile/run php everytime a request is made??? I am
not sure about this?

 Yes, but do you want your web designer going
 through your perl code

Hmmm, good point, hehehehe...



Thanks a lot for your time and I appreciate your
comments.

Baho...

__
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Bora Paksoy

 Threading instead of forking?  None of these do
 either.  Apache is a
 pre-forking multi-process server and both PHP and
 mod_perl are part of
 these pre-forked processes.  Neither mod_perl nor
 PHP do any threading nor forking. 

??? I didn't get this? Aren't these pre-forked
processes handle requests using threads internally?
Say you configure apache to pre-fork 5 server
processes, what you are saying implies that you can
only handle 5 concurrent requests?? can you please
explain this more?

 Again, the architectural difference makes this a lot
 easier to do in a
 single-process JVM scenario.  Note that such a
 single-process JVM
 architecture which maintains static objects is very
 hard to scale cleanly.

Actually, as far as I know, you can configure tomcat
or other servlet engines to start multiple servlet
engines (JVMs) and the dispatcher code makes sure that
every user goes to the same JVM for subsequent
requests. So, you can scale with this architecture...

 The lifecycle of a request/response matches the
 lifecycle of an HTTP request/response.

Actually, I was asking the low-level information, I
mean something like web server receives the request,
hands this over to mod_php, that requests a thread
from the worker threads, so on so forth...

Anyways, once again, thanks for your time...
Baho.

__
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Rasmus Lerdorf

 ??? I didn't get this? Aren't these pre-forked
 processes handle requests using threads internally?
 Say you configure apache to pre-fork 5 server
 processes, what you are saying implies that you can
 only handle 5 concurrent requests?? can you please
 explain this more?

That's exactly what it means.  Apache on Unix is non-threaded.

 Actually, I was asking the low-level information, I
 mean something like web server receives the request,
 hands this over to mod_php, that requests a thread
 from the worker threads, so on so forth...

Well, since there are no threads involved here there is no pool of worker
threads or anything like that.  You simply have a process that grabs a
requests, branches off to mod_php/mod_perl and sends the result back.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Rasmus Lerdorf

 I mean, for example say you have
 an html that consists of blocks... Making every block
 an include is clean, but this time, php engine has to
 read all of these includes, and parse the html+php and
 compile/run php everytime a request is made??? I am
 not sure about this?

I wouldn't say it was clean to split everything out into separate files.
I tend to do something more like:

  ? include 'logic.php' ?
  HTML tags tags tags
? my_func() ?
  More tags
? another_func() ?
  More tags
  ? footer() ?

ie. don't necessarily use 1 file per block, create functions that are
defined in a single file and call those instead of including a new file.
If you really do want to separate it, have a look at a cacheing templating
system like Smarty which lets you keep this per-file separation but it
caches the combined logic.

  http://www.phpinsider.com/php/code/Smarty/

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread speedboy

 ie. don't necessarily use 1 file per block, create functions that are
 defined in a single file and call those instead of including a new file.

How do you echo your html, do you put the html in your functions and
escape the double quotes? There is some extra load there echoing all the
html?

Thanks.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Rasmus Lerdorf

  ie. don't necessarily use 1 file per block, create functions that are
  defined in a single file and call those instead of including a new file.

 How do you echo your html, do you put the html in your functions and
 escape the double quotes? There is some extra load there echoing all the
 html?

echo HTML?  I do this:

  ? php stuff..?
  HTML stuff
  ? more php stuff ?

I drop out of PHP mode to display raw HTML.  If I have a lot of HTML with
a lot of PHP variables tossed in, I do:

  ?
   $test = 'test';
   $one = 'one';
   echo EOF
   This is a $test.
   And here is another $one.
  EOF;
   ..more php code...
 ?

Or sometimes simply:

  HTML stuff ?=$variable? and some more HTML stuff.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP vs. PERL (Functional Comparison)??

2001-09-16 Thread Jack Dempsey

hallelujah...first time i've seen someone else mention here docs, and being
rasmus, not a bad person to make the mention ;-)

-Original Message-
From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 17, 2001 12:17 AM
To: speedboy
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] PHP vs. PERL (Functional Comparison)??


  ie. don't necessarily use 1 file per block, create functions that are
  defined in a single file and call those instead of including a new file.

 How do you echo your html, do you put the html in your functions and
 escape the double quotes? There is some extra load there echoing all the
 html?

echo HTML?  I do this:

  ? php stuff..?
  HTML stuff
  ? more php stuff ?

I drop out of PHP mode to display raw HTML.  If I have a lot of HTML with
a lot of PHP variables tossed in, I do:

  ?
   $test = 'test';
   $one = 'one';
   echo EOF
   This is a $test.
   And here is another $one.
  EOF;
   ..more php code...
 ?

Or sometimes simply:

  HTML stuff ?=$variable? and some more HTML stuff.

-Rasmus


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]