
|
View Full Version : JSP vs PHP
Knogle 03-07-2004, 10:32 AM I've seen enough PHP vs Perl debates; and that set me thinking. How about PHP vs JSP? I don't think many comparisons have been made between the two above mentioned languages. What language would you recommend joe average to use? Who would you recommend to use which language? Which language would you use for what purpose?
My personal observation is that many large institutions or companies tend to use JSP, while smaller companies generally use PHP. I don't know why -- perhaps it's infrastructural cost of running JSP? Or JSP just looks more professional?
Please enlighten us, oh gurus. ;)
Rich2k 03-07-2004, 11:01 AM Not really.
There is no best, just what you want to do with it.
J2EE personally I find to be quite slow.
However when companies like yahoo use PHP instead of C++ you know that PHP can cope with large scale enterprise coding.
PHP 5 will be even better for OOP (which is where JSP certainly has an advantage over PHP at the moment).
Knogle 03-07-2004, 11:13 AM Many people I speak to advise me to use PHP for small projects like a simple guesbook, and JSP for large applications. Why is that so?
I know a major setback of JSP compared to PHP is that it consumes memory - a ton of it. But it's more scaleable compared to PHP.
My question is -- why? ;)
stdunbar 03-07-2004, 12:35 PM Disclaimer - I do Java/J2EE for a living. I know little about PHP.
From a memory perspective if you have 1000 simultaneous visitors to a JSP there is only one instance of that JSP in memory. So that is one way that J2EE helps with scalablility. Java requires threads and J2EE uses them all over the place. As threads are traditionally less heavyweight than multiple processes that can help with scalability too (though the braindead threading model of Linux limits this some for Linux based installations)
The most recent Tomcat - the Apache server that has JSP's and Servlets - allows for a clustered configuration for load balancing and failover. So I can have 10 servers that look like one. Commercial J2EE servers, which add significant other capabilities, also have commercial grade clustering and failover.
Lastly, there is the matter of design capabilities. How do you implement an MVC architecture in PHP? How do you implement solid object oriented design patterns? My understanding is that PHP is getting these capabilities at some point in the future.
As Rick2k said, alot of it has to do with what you want to do. I can write a guestbook in JSP's and servlets in a very short period of time. I can write it to look like C with functions and no OO (like all the PHP I've seen).
Or I can also use tag libraries, servlets and an MVC type pattern to greatly simplify adding multiple languages/locales, changing my database and not changing any JSP code, and putting that guesbook into a full eCommerce system. Certainly most of this is possible with any well written system. I feel that the design patterns encouraged by Java and J2EE make is easier.
bigwrench 03-07-2004, 01:15 PM I think the key difference is scalability. Java can grow and stay organized, Perl falls apart when it gets too big. As a result, PHP is perfect for small or self-contained web applications like phpBB.
JSPs can do the same as PHP and go far beyond. Java was created to easily handle large, distributed applications, with its highly structured object organization. JSP is Java's form of hypertext processor.
Rich2k 03-07-2004, 02:02 PM Yes but PHP can cope with large scale usage otherwise people like Yahoo wouldn't be using it to power many of their sites.
The closest I come to using J2EE though is using cold fusion MX which sites on a J2EE infrastructure.
cleaver 03-07-2004, 04:38 PM I do mostly Java/J2EE. I've done a little bit of PHP too.
Personally, I wouldn't recommend anyone use JSP on it's own. JSP gives you just another page scripting language, not much different in concept from ASP/PHP. IMHO, JSPs are valuable as part of the J2EE architecture, combined with Servlets, EJBs and other components of J2EE. As mentioned, the architecture encourages the use of the Model-View-Controller pattern (MVC).
J2EE is suited to larger, more complex applications. It scales well in terms of code maintenance: you can extend your applicaiton without turning into spaghetti. It also scales well in terms of volume: if you need more power, just add another server to work in parallel.
J2EE in my experience is not slow, if you follow accepted patterns. It does offer lots of opportunities to write slow code, if you don't architect your app correctly.
PHP while, not object-oriented in the manner of Java, does let you follow MVC after a fashion. (I wrote my PHP this way, under the influence of Java.) PHP is pretty fast, but to scale to more volume would require you to design the parallel architecture yourself. J2EE give it to you out of the box.
Bottom line: If you are writing just a few screens, and don't expect a lot of complexity, use PHP. If you are writing enterprise software, or want to beef up your credentials :), go J2EE. Don't use JSP on it's own.
oldunis 03-07-2004, 06:29 PM I really prefer PHP... it is very flexible... and all the above mentionned :D
D0mainGuru 03-07-2004, 07:44 PM Php is overall much better :), and with php 5 coming it should become the best of the best in all areas.
bigwrench 03-07-2004, 10:49 PM I think I erroneously placed Perl in place of PHP, oops. One very nice thing about PHP is its impressive response time. It's loaded as a module when Apache starts up so it's always running, with zero load time when pages get requested.
acewebi 03-08-2004, 12:07 AM php also has bult in global variable unlike perl, perl does have global variables but not nearly as many as php... :)
above all php is much more easier to learn :)
innova 03-08-2004, 02:21 AM though the braindead threading model of Linux limits this some for Linux based installations
How so?
Can you elaborate on this?
Is there a distinction between the 2.4.x kernels and the 2.6.x?
stdunbar 03-08-2004, 03:05 AM Linux does not truly do threads like Solaris, HP/UX, AIX and, yes, even Windows. The native thread model in Linux requires a process for each thread, similar in concept to the old fork()/exec() model in C. While clone(), the Linux variation on the theme is more efficient that fork/exec, it is still a 1:1 scheduling model - for each user space thread there is a kernel process. Most other O/S's have an M:N model. There may be many user level threads for a single kernel thread and a particular user thread can be moved between kernel threads. Linux has no concept of kernel threads since everything is process based. I'm most familiar with Solaris and the Solaris kernel has been multithreaded for years. The kernel itself can take advantage of a 64 CPU machine, not just userland processes.
In effect, Linux threads are pretty heavyweight. RedHat and others have done tests with new threading models. I found an article at http://www.onlamp.com/pub/a/onlamp/2002/11/07/linux_threads.html that gives you an idea of the overhead of Linux threads.
As Java was built from day one to be multithreaded it can perform poorly with thousands of threads under Linux. As an architect I have to be aware of that. I develop on Solaris, Linux and, when forced to, Windows. Linux is the only one where I have to worry about having 1000 threads.
bagpuss 03-08-2004, 07:14 AM PHP is great for small to medium projects, but way behind J2EE for big projects, people have already mentioned scaliabilty, but what is also somewhat related is standardization, with J2EE you have you have Sun in control and a few standards, whilst PHP is all over the place.
When working on a J2EE project it doesn't matter which company / people I work with, they will all know the core framework and J2EE technologies, but with PHP even something as simple as tgas / templating is a knightmare, some people use smarty, others fasttemplate, others their own custom system and so on, so either I have to learn yet another templating system or they have to learn one I know. And that's just templatimng the same goes for many other tasks in PHP which are not built in so you get a hundred different versions, I know they have PEAR, but the problem with that is the low quality of some of the classes, which is why people write their own.
werfew 03-08-2004, 12:59 PM Originally posted by cleaver
I do mostly Java/J2EE. I've done a little bit of PHP too.
Personally, I wouldn't recommend anyone use JSP on it's own. JSP gives you just another page scripting language, not much different in concept from ASP/PHP. IMHO, JSPs are valuable as part of the J2EE architecture, combined with Servlets, EJBs and other components of J2EE. As mentioned, the architecture encourages the use of the Model-View-Controller pattern (MVC).
J2EE is suited to larger, more complex applications. It scales well in terms of code maintenance: you can extend your applicaiton without turning into spaghetti. It also scales well in terms of volume: if you need more power, just add another server to work in parallel.
J2EE in my experience is not slow, if you follow accepted patterns. It does offer lots of opportunities to write slow code, if you don't architect your app correctly.
PHP while, not object-oriented in the manner of Java, does let you follow MVC after a fashion. (I wrote my PHP this way, under the influence of Java.) PHP is pretty fast, but to scale to more volume would require you to design the parallel architecture yourself. J2EE give it to you out of the box.
Bottom line: If you are writing just a few screens, and don't expect a lot of complexity, use PHP. If you are writing enterprise software, or want to beef up your credentials :), go J2EE. Don't use JSP on it's own.
cleaver:
you can use MVC, actually there is a port of Jakarta Struts in PHP.
It's called phrame ( http://phrame.sourceforge.net/ ).
I think if you are commited to create a really big applicaion the solutions is MVC (i started studying it, but haven't had much time to dedicate to it lately).
On the other hand, there's something in php that you don't have in JSP, which is a really good (and serious) template system like Smarty. (http://smarty.php.net )
Well, i just wanted to mention that since you might probably didn't know about it.
See you.
- Werfew
inFused 03-08-2004, 05:21 PM I prefer PHP, and use it when coding my web-based applications.
cleaver 03-10-2004, 07:10 PM Originally posted by werfew
cleaver:
you can use MVC, actually there is a port of Jakarta Struts in PHP.
It's called phrame ( http://phrame.sourceforge.net/ ).
I think if you are commited to create a really big applicaion the solutions is MVC (i started studying it, but haven't had much time to dedicate to it lately).
On the other hand, there's something in php that you don't have in JSP, which is a really good (and serious) template system like Smarty. (http://smarty.php.net )
Well, i just wanted to mention that since you might probably didn't know about it.
See you.
- Werfew
Thanks, I didn't know about pframe... I think you can really do MVC in any architecture.
I didn't look to close at smarty, I assume it would be similar to Tiles templates in Java. There are some other ways to do this in Java too.
cleaver 03-10-2004, 07:14 PM Originally posted by D0mainGuru
Php is overall much better :), and with php 5 coming it should become the best of the best in all areas.
I wouldn't say any technology is better, myself. PHP is great, but it depends on what you want to do.
There's some great stuff in J2EE, like message-driven beans, but not every webapp will need that kind of technology.
I like the Swiss army knife approach... You can pull out the best blade for the job at hand.
ilyash 03-10-2004, 10:39 PM I think the reason most professional companies use Java rather than PHP
is because PHP is a dirty language.
It is not as organized as java.
In java you have classes/packages/methods
PHP has just methods..
It makes the code messy
Rich2k 03-11-2004, 05:15 AM You have classes in PHP
stdunbar 03-11-2004, 12:22 PM Again, I know little about PHP but am trying to learn so please bear with me.
When using a modern JVM (<2 years old) frequently used code is compiled into native code inside of the JVM. This is truly native code like a compiled C or assembly program. In this way the JVM no longer has to interpret the byte code of the Java classes.
I'm still learning about PHP and my understanding is that, out of the box, PHP must reinterpret the PHP code with every call. If 1000 people request a PHP file that file is reinterpreted 1000 times. What does the add on Zend optimizer do? Based on my reading it seems to add some sort of caching to the interpretation - in effect compiling the code and doing something similar to the JVM though it is unclear to me what level it takes it to - is it an intermediate neutral format or is it native code?
I'm not interested in a religious war - I'm just trying to understand better.
Thanks for your feed back.
Rich2k 03-11-2004, 07:08 PM Yep software like ioncube accelerator and zend add caching to PHP.
|