General Question

HungryGuy's avatar

What are the differences between Perl, PHP, and Python?

Asked by HungryGuy (16044points) January 15th, 2010

Are they all similar in syntax? Or are they each fundamentally different? Will they all work with MySQL and MS-SQL? Are they all supported equally by Apache?

Observing members: 0 Composing members: 0

26 Answers

BhacSsylan's avatar

Um, i unfortunately cannot answer this question, but I have to ask: why the NSFW tag?

Ivan's avatar

Testicles?

J0E's avatar

NSFW? Perl or pearl necklace?

HungryGuy's avatar

@J0E – Maybe a Perl Necklace will make her SQL with delight :-p

casheroo's avatar

I feel lost..is this sex? computers? Where am I?

knitfroggy's avatar

glad I’m not the only one that’s confused…

Simone_De_Beauvoir's avatar

wait are these dildos?
in all seriousness they are different programming languages and they will probably all work with MySQL.
Gosh, Simone, you’re so smart!
no, husband’s sitting next to me. sigh

Sarcasm's avatar

@HungryGuy A perl necklace from your python?
I see why this was NSFW’d now.

mowens's avatar

I think he did it to get attention. Don’t blame him, got me to click on it.

HungryGuy's avatar

Removed by Masters and Johnson.

ETpro's avatar

Similarities are that all three are Open Source with active support communities. Perl and Python are rather similar, and both quite different from PHP.

Perl is a high-level, general-purpose, interpreted, dynamic programming language. It draws many of its features from languages such as C, Shell Scripting, sed and AWK. It has powerful text manipulation capabilities and is capable of interfacing with a number of databases. On the Web, Perl is often used to write Common Gateway Interface (CGI) scripts to connect HTML pages running on a Web server to other server resources such as sendmail, etc.

Python is a general-purpose high-level programming language that places emphasis on human-readable syntax. Python supports multiple programming paradigms (primarily object oriented, imperative, and functional) and features a fully dynamic type system and automatic memory management, similar to Perl. It too is often used for Web CGIs. I haven’t seen any studies of preferences, but just from what I see in working on various existing Web sites, Perl seems to be the most commonly used language for Web CGIs.

PHP is a scripting language designed from the ground up to be used in Web pages. Unlike the above high-level languages, snippets of PHP code can be embedded right within the source code of an HTML page, adding server-side intelligence to what would otherwise be a static page. PHP is designed specifically to interface easily with SQL databases, and can also be used with other high-level databases. While PHP can do image processing, calculation, and database querying, it generally passes off jobs requiring a high0-level language to a CGI script which might be written in Perl, Python or any of a ton of other ingredients of the alphabet soup that is modern programming.

HungryGuy's avatar

@ETpro – So if I were do develop a web site, I couldn’t do it entirely in PHP?

ETpro's avatar

@HungryGuy That all depends on what you want to do. PHP has the horsepower to completely handle most things you need to do on a Web site.

HungryGuy's avatar

@ETpro – I want to build a dating website. People will register, update their profile, post personal ads with avatars/photos, and answer ads of others. Perhaps there’ll be a webchat feature where people can chat together without revealing their IM or emails to each other. A nightly batch script will analyze everybody and recommend matches. It’ll generate emails (if you’ve requested them) alerting you to new matches. If the site gets popular, there may even be a few googleads placed here and there. You know, a typical website…

ETpro's avatar

@HungryGuy You can do all that in PHP. However, should this take off and start getting really heavy traffic, you might find that the server demand is getting hard to sustain. If you think it has a shot at real success and can afford the consulting, get some advice from an expert in heavy traffic sites on what parts to handle in a scripting language like PHP and what to spit off to a high level language or to compiled code. You will want to cache PHP output and leave heavy processing tasks to cronjobs. You’ll want to heavily optomize your database including saving sessions in it. Work on strategies to save some sockets. Optimize Appache.

I’ve seen the meltdowns now on several social Q&A sites where these steps were ignored in the rush to get started, and the sits hit a point where the old way of doing things became unsustainable with the traffic they were generating. It’s not a pretty sight.

HungryGuy's avatar

@ETpro – Really? Social Q&A sites? You mean like Fluther? Is Fluther in danger of exceeding its server capacity?

But nah, I don’t think I have to worry about competing with the big guys. It’ll be just a little free site that pays for its hosting expenses with adverts. Though, if you’re saying that a compiled language (like Perl or Python) is more robust than PHP, I’d like to give those others serious consideration (I’m a COBOL PL/1 DB2 CICS programmer in my day job, so I’m not afraid of using a “real” programing language). Up to now, everyone has recommended PHP to me hands down.

BTW, I want everything to run in real time. The only thing I can see to give to a cron job is the nightly “matchmaker” process…

ETpro's avatar

@HungryGuy I don’t know about Fluther. I haven’t looked at how its back end is structured. The fact they do not allow image or video uploads may indicate they gave some serious thought to how to handle heavy traffic as they were specing out the site. Answerbag was a good example of a pure meltdown. In their makeover, they took out the features that were draining system resources. Unfortunately, those were the same features that made the site do much fun to use.

HungryGuy's avatar

@ETpro – You got that right! They removed the features that made the site so bloody addictive!

ETpro's avatar

@HungryGuy BTW, the feature here that shows when a user is drafting a response and identifies what user it is is most likely producing a lot of server cycles. It may be one thing that has to go if the site gets really popular.

HungryGuy's avatar

@ETpro – Yup! I wondered why they even have that feature here. Like, who cares how many people are observing the question or composing a response!

ETpro's avatar

@HungryGuy It adds immediacy and shows that the site has lots of users active at any given moment. But it’s gotta be resource hungry.

HungryGuy's avatar

@ETpro – I suppose that’s true. In the case of our conversation here, I suppose it would be nice if they actually listed the names of the two of us observing this question. But then again, I’m all over the place. After posting this reply, I’ll go and reply to some other question and come back again when I see it come up agaion on my Activity list. I might even pop over to AB, or Blurtit, or eBay for a few minutes and then come back. So even that wouldn’t prove anything. I agree it’s a probably resource hog that gives little benefit.

noyesa's avatar

Perl and Python aren’t compiled languages. Additionally, PHP has no relationship to either language. Once upon a time PHP was technically a collection of Perl scripts, but the modern day PHP has absolutely no connection to Perl other than a few syntax similarities. The standard interpreters for these languages are all written in C, and most use the same C libraries behind the scenes to do most of their work, like image processing or networking.

For creating a website I would use PHP. It’s fast, generally very lean, easily integrated with many third party components for things like caching and database access, and has the most complete database layer out of the box.

Even though lots of people are still using it, Perl is generally not a major player on the web these days. Python’s influence is quickly increasing due to the Django framework as well as Pylons and several other frameworks, but the point is that Python isn’t very fun to work with without a framework since it’s purely CGI. Developing websites with Django is a highly structured academic approach to web development, designed by people who wanted to abstract the mundane details of developing complicated web applications. It’s not something you pick up in a weekend, to put it bluntly.

PHP works on the web through CGI just like the others, but it is also a domain-specific language: it’s tailored for writing web applications, and as such offers a lot of convenient abstractions that make focusing on web development that much easier with PHP.

The language syntax itself is a mixture of C and Java with a few deviances from both, but if you’re familiar with either you shouldn’t have trouble picking up on PHP. This is what makes PHP so easy to learn if you’re already used to C/C++ or Java, since you can jump right into the technical details and not waste your time learning syntax or semantics. Perl has a lot of its own quirks that differ from most other languages, and Python is probably not like much else you’ve used before so don’t expect to be able to pick it up quickly.

PHP’s object-oriented syntax is a lot different from C++, quite similar to Java, but it’s very simple and well-designed (shockingly enough; PHP isn’t known for its cleanliness…) and isn’t too much to handle.

And in the end, if you decide that you want the convenience and automation of a framework, PHP has several frameworks that are as mature as anything you’ll find for Ruby or Python. symfony is a personal favorite, but CakePHP, Zend, and CodeIgniter are other popular PHP MVC frameworks, written to solve the same problems Django was.

HungryGuy's avatar

@noyesa – PHP sounds like what I want. But I’m concerned about performance issues and that I might be better off using a compiled language in the long run as @ETpro mentioned above.

noyesa's avatar

I don’t think that’s going to be an issue. A well written PHP application will be more limited by the HTTP protocol or database access than execution time. Even the most massive server-side applications are written in scripting languages, for web sites that recieve millions of hits and rely more heavily on server-side processing.

HungryGuy's avatar

@noyesa – Well, okay. Since I’m new at developing a web site, I see the value in getting it up quickly in PHP. Then I can write the next version in a more pure CGI language if I’m so inclined (provided that access to my database with MySQL remains consistant).

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther