I am not interested in knowing which of these languages is better. I simply want to know some facts about them. I am starting this thread here because at my local university this has become a religious topic. Example: “- PHP is good for small pages but for large projects you have to go with Java” “- Why?” “- Because you just can’t compare small forum sites to a REAL project” “- Why?” … ad infinitum.
So, please, I would like to know some factual advantages/disadvantages between the two.
BTW, I have programmed in both languages, not much though. I believe PHP is faster but for what I’ve read at that mentioned discussion I could be wrong.
Comparing the two is hard, because they’re really made for different tasks.
PHP is something I would use if I needed to do some dynamic front-end work with a web site. You can get code up and running fairly quickly, and get results toot sweet. On the other hand, I wouldn’t try anything really complex with PHP, such as building a secure online job-recruitment and database site.
Java is better for larger, more complex, software systems. You’re not limited to web pages and front-end work, you can’t do crazy-ass things the way PHP lets you, and it’s generally more robust for the job at hand. On the other hand, using Java to just make a dynamic web page is like using an 18-wheel semi truck to go buy groceries at the neighborhood 7-11.
(Then there’s JSP, which combines the Java language with PHP’s front-end goofiness, but that’s a different kettle o’ fish)
PHP can be used for very, very large projects successfully, and I’m not aware of any serious barriers to implementation. PHP has tons of functionality for easy connection to databases, which is very nice.
The built-in function library of PHP is very extensive and powerful. It’s been my most favourite language to program in since I learned it. I like to say “PHP is like having a toolbox that every time you reach in you can find the tool you need.” Fierra recently took a Java class where the instructor claimed that PHP was slightly faster than Java, but no citation or proof was really offered.
I’ve tried learning both languages, and I picked up PHP and became quite skilled with it, doing things I didn’t know was possible to do, within a week. With Java I spun my wheels for some time to do what I can whip up over a lunch hour in PHP. However, that is not to say Java is bad or not as good, or not better, just to say that I believe that the barrier to learning is much lower with PHP.
I’ve done both Java (Java Servlets) and PHP on the internet.
A well written PHP application can be just as secure as a Java application, problem is many people who are just coders, and aren’t really concerned with security can learn php - and they make mistakes.
You can make exactly the same mistakes in Java on a server, such as not validating input as it comes in the script and allowing that code to be run in a database or directly on a server, but that is neither here nor there. 99% percent of wholes on webservers come from insecure coding practices. Java lets you be almost as insecure as PHP can be - but since many more Java programmers come from an engineering or computer science background, and more PHP coders than Java coders are self taught - there may be some truth to the rumours that Java is more secure, simply because Java programmers are trained beyond PHP programmers and make less mistakes.
PHP is meant to run via a webserver, and use system calls on the operating system, or make calls to a database, but it is for CGI based applications.
if you want to create standalone application, you will need java, if you are talking about making calls to a database and displaying data - either will work, but PHP is easier to learn, and it is highly scalable:
There are well built open source modules for database abstraction (there is internal drivers for all of the major databases), and libraries for many complex things available, and by the way the SDMB uses PHP for the forum, with the high level of traffic - and from my memory we’ve only had one time where they recommended everyone change their passwords due to a hack, and then after upgrading the forum software it was no longer an issue.
PHP is an excellent language for dynamic server pages, everything from secure job-recruitment sites to complex database driven sites, and can be very secure and scalable if programmed with security in mind.
wholes == holes
From a pure language design point-of-view, PHP and Java are two different animals.
PHP is very polymorphic by design, with no strong typechecking or serious restrictions designed at enforcing linguistic purity or code hygeine. PHP is designed from the notion that you will be embedding small, self-contained programs wherever you need them, without putting too much thought into writing the code itself.
Java is more static, with a strong typechecking mechanism and some restrictions that attempt to enforce what the Java design folks think is good practice. Java is designed from the notion that you will be writing larger, more complex programs with lives of their own, and you want a language that will watch your back more than PHP does.
It’s a matter of style and personal preference, to some extent. Do you come from a C++ background and expect a compiler to make sure your code makes sense? Try Java. Do you want to write code at the algorithmic level and have the computer deal with as many of the details as it can? Try PHP. Both are capable of doing pretty much anything at this point.
(And if you decide you like the PHP way of thinking, try Perl. Una, the `full toolbox’ feeling is very much a part of the Perl worldview. ;))
Hey Orlamo,
Welcome to the SDMB!
In general, it’s probably best to start a new thread than resurrecting a 14-year-old one. Both technologies have changed a lot since then.
In regards to PHP performance, you can easily cache data in redis or memcached, or if your architecture allows it, cache the entire output of your PHP behind something like Cloudflare (which is really, really great for this) or Pantheon or DIY it with Varnish. These days, most PHP-based apps already have multiple caches built-in, and PHP7 also precompiles the scripts for you and caches those too.