I maintain a site that receives over half a million pageviews per day, not including API requests of XML feeds. This site runs on 3 medium range commodity web servers and 2 database servers, and there's plenty of capacity left.
Don't let the scaling police and architecture astronauts fool you: with the right architecture in place (i.e. a framework like Cake or Zend) and a smart scaling strategy (opcode caching, object caching, page caching, etc), PHP is a great choice for web applications.
Sure PHP has a low barrier to entry, which can lead to poor coding practices, but that shouldn't be a reason for people to express an absolute hate for it. Rather, it's important to stress continual education regardless of which programming language you choose.
Everyone is going to put up an argument for different languages. There is no magical language that works for everything. It really depends what the project is.
With that said. I work on a PHP site that does 5-9 million page views a day. We have an in house MVC framework. We use MySQL, memcached and APC hosted on a handful of solaris zones. We have no issues scaling and have coding policies that our development team tries its best to follow. PHP is a proven language, it has been around a long time and has a huge community. It really comes down to preference and objective. I personally don't use any of the open source frameworks available. But there are plenty of decent ones that will work just fine for small to medium sized sites.
To anyone who says thats it's not a "real" language: do I care? It gets the same job done, it's proven to scale and it can turn a profit. Period.
Sure, it scales. But it isn't a very good language. (The word "blub" comes to mind.)
Here are features I like to have (in no particular order):
* lexically-scoped variables (and closures)
* lambdas
* continuations
* macros
* an object system with a MOP (PHP and Java fail miserably here)
* powerful regex engine (can be added via libraries, so not too critical)
* extensive module library
* flexibility (I want to write code my way, not the way someone else thinks I should write it; bye bye, Python.)
PHP has none of these features. That's why I don't use it and don't recommend it. And oh yeah... PHP is a templating system too. I would rather get that as a library, not a core feature. (But I won't count that against them.)
So what language does have all these features? None :)
But, Lisp and Perl are good compromises. CL does everything except continuations and having a decent module library; Perl does everything except have pretty syntax and macros. Sadly neither of those languages has (by default) the "optional features", which is a shame. I ranted about this on my blog:
Anyway, PHP is junk in terms of a programming language. It's fine if you don't know how to program, don't know what abstraction is, and don't like using libraries.
True of maybe half of those features...but the other half? Well, if you don't know enough to miss them, I don't have any way to argue with you--there's no common language in which we can converse about them.
But, I feel uncomfortable every time something I write takes two or three times the lines of code because of what the language lacks. First class functions or lambdas, closures, and a good library fall into this category...and PHP fails on all of them (there are many PHP libraries, but most are buggy and rather scary, and the standard library has ad hoc'ery written all over it...I like for the standard library to at least be a little bit planned out rather than crammed in via 3000 or so functions in the same name space).
But PHP is a perfectly valid language for many classes of problem. Just be careful not to use it for the classes of problems for which it is extremely poorly suited.
>Well, if you don't know enough to miss them, I don't have any way to argue with you--there's no common language in which we can converse about them.
While I agree with your actual premise ; this statement is pretty bad form. It is the logical equivalent of a Christian saying that in order for me to critique his faith, I must become a Christian.
Replying, "you wouldn't know; you're an imperative programmer" is moot; maybe he is an imperative programmer - but he could also be correct. There is no connection between the two. Deductive logic has never been allowed in the scientific method, which is, ultimately, the barometer of truth.
I'm aware that Graham is the originator of this somewhat popular meme, but it's a wrong popular meme. The nature of ignorance of certain desirable features can only explain why people don't immediately demand them; it doesn't prove their usefulness.
"Replying, "you wouldn't know; you're an imperative programmer" is moot"
That's obviously not what I said. My reply was, "If you believe all of the features listed above are useless in a real world development situation, I'm not capable of convincing you otherwise, as we're going to be speaking very different languages". I think there is a difference, though I can see how it comes off as arrogant. It wasn't really intended that way--I'm not a great programmer, and never claimed to be. But I know what makes me (as an adventurous, but not necessarily brilliant, hacker) more productive is good tools. And first class functions, closures, and a great set of libraries (like that found in Perl, Python, and to a lesser degree Ruby), are the tools save me lots of time. When I develop in PHP, and I do so pretty frequently, I miss all of those features constantly and my code is longer, less readable, and harder to maintain.
My point was if you haven't worked with a language that has those features you wouldn't be aware of how much time, and how many lines of code, they can save you. I'm not a smug lisp weenie pushing the blub paradigm (though there is definitely something to the argument) or implying that imperative developers are the scum of the earth. I'm a pragmatic sort of fellow...if it works, use it. But if something works better, why not use it instead?
That said, one of the places where PHP is a perfectly valid language is web applications. Some of the largest applications in the world run on PHP--Facebook, many Yahoo sites, etc. But they also have lots of languages doing the non-frontend work, because PHP is really horrible at a lot of backend tasks. Data and systems management, for example, where Perl and Python, or Java (depending on scale and performance requirements and existence of libraries), would be a better choice.
Sorry, I didn't mean to characterise you wrongly, I only rephrased the actual quote because it fitted better with the deconstruction. I actually do think it's a reasonable representation of what you said (or, more pointedly, the concept in general).
Good reply, looks like I made a mistake about part of your opinion, but I can't agree with you about not being the value of these features being difficult to explain. I always just explain situations where closures/anonymous functions work well (while I'm not much of a web programmer, I can think of a couple of examples). I agree, there is something to the blub concept. There certainly is a spectrum of languages.
Certainly not. I've used every feature in his list, except partial evaluation in a real program. Partial evaluation would have helped immensely, but it wasn't available in any language I've used. I admit that continuations weren't really necessary, but they do make code with backtracking much easier to read.
And here we have an architecture astronaut. Once you get out of academia and start programming in the real world, you'll realize that there are other considerations for determining which programming language to use besides a robust feature set.
So go write your program in Lisp, but don't complain when you discover how few developers out there are capable of maintaining such an application.
Is English, with its hundreds of rules and exceptions, the best spoken language to communicate in? Of course not. But it's ubiquitous, and that's all that matters.
Though I haven't met him in real life, I'm quite familiar with jrockway's work and he's hardly an "architecture astronaut" or in academia. He's a good programmer who gets real world work done. And guess what? I find his code well-written and easy to maintain. Go figure ...
Just because you don't need the items on his list, don't going throwing stones at those of us who do. You'd be like the people who rush out competitors to Microsoft Word on the theory that people only use 10% of the features -- only to discover everyone's using a different 10%.
I would add: A debugger that works, and an IDE that helps you get the job done (versus endless cycles of "print" debugging).
I'd rather use a moderately crappy language in a decent development environment than a wonderful language that was lacking tools support. It's not all about the language.
PHP is horrible but not because it lacks continuations or macros or partial evaluation.
PHP is horrible because it is like an higher level of C, with an horrible standard library where the same thing can be done in 5 different ways, without literals for the most basic data types like arrays, without the simplest meta-programming abilities (assuming you don't want to use eval of course), OOP in theory (with an horrible OOP system for a dynamic language) but with all the base types that are not, and so on.
Hmmm... Interesting that, without cause, you gave such a defensive reply. I take it PHP has gotten a bad rap an not scalable? Any language can scale, if the implementation is designed correctly.
PHP is without a doubt the worst structured language I've ever coded in. Probably the crappiest language after VBscript.
But I use it for anything web-based because it gives me guaranteed results, anytime, anywhere, on whatever scale on whatever budget. I just wouldn't use it for sites with complex business logic, but let's face it, most websites, even the big ones, are hardly rocket-science in that respect.
What I love most is the dynamic of the PHP community. For instance, when RoR arrived on the scene, the response wasn't to dis RoR or run scared, but more like "that's so cool, let's see if we can bring PHP to that level". And there is more sharing of knowledge and experience (and code) going on inside the PHP-community then any other developer community I know.
More then any development platform I know, PHP is alive and constantly developing, but still as easy to deploy and easy to learn as ever.
The only thing that's really good about PHP is the easy deployment. You just upload your files to your server and it works. The language is very crappy, so this easy deployment only outweighs the extra development effort up to a point. I'd recommend against it for sites that take more than two days of work. With services like Heroku, deployment with Rails may have become as easy as deployment with PHP.
Ruby and Python seem to be the current preferred languages.
I've used PHP for a while -- a few years -- and haven't developed a particular loathing for it. That's saying something, since I'm disgusted by most of the tools I'm forced to use.
It's certainly capable enough and isn't hard to use. It's also more ubiquitous, and therefore arguably more portable, than Ruby or Python, although dealing with differences between PHP versions is a pretty royal pain.
Pretty much any reasonably skilled programmer can do a job in PHP without too much trouble. You'll get more cred for using Python or Ruby though.
There are also a lot fewer Python, Ruby and Django jobs than PHP jobs there so you would expect to see more low/entry level PHP jobs in there pulling the average down.
PHP is a brilliant language for small to medium-small sites.
Since most medium-small sites have an irrepressible tendency to grow into medium and even large sites, I'd stay away from PHP for anything other than a quick and simple site.
Ruby and Python are much more sustainable in the medium term and even the long term, and just as quick to throw applications together. Sure, they won't last forever, and eventually you may have to rewrite critical bits in another language, but in the meantime it works to release something quickly and keep improving it for a few years.
As a language for developing applications, PHP really isn't that bad. It has pretty damn good support for OOP (at least within recent releases). It lacks in concurrency support and other random things like namespaces (for which swombat advised against large-sized sites).
As a language for scaling... not too shabby. Many people who bash PHP for inability to scale really don't know jack shit about what they're talking about. Chances are, their app is slow because of all the O(n^2) loops... and they need to go take a class or two on algorithms, networking, and/or distributed systems.
I used to work with PHP a lot... eventually moved to Python simply because it was more succinct. Our teams are extremely small, and we needed a more expressive language; needed to get more done in less time. The rest speaks for itself...
We actually have moved from 100% PHP to: python for web apps, decent amount of Io & Ruby for utilities/monitoring and such, and working on a load balancer in Erlang... much more powerful development. And we really haven't run into many major stability problems...
Are you speaking in terms of traffic? Several very large sites run on PHP (Facebook comes to mind) while few run on Ruby (I think Twitter tops the list).
RoR is an architecture. Kind of ironic because I claim that Ruby, as a language, has better support for scaling in the networking/dist.systems view than PHP. Yet, I would like to claim that PHP scales better than RoR in the web app domain. Though, it takes deep knowledge of RoR internals to make a correct judgement; which, very few have.
It's strange that nobody has mentioned that Yahoo! uses PHP to power a lot of their software, and it obviously scales very well if you know what you're doing.
They also remarked that they are looking into using Symfony framework in their software.
I wouldn't consider Yahoo the pinacle of software engineering, or a hotbed for inovation. For a company of their size, they are not releasing any groundbreaking features, or anything too advanced, and they are obviously trailing google by a big margin.
Facebook and Digg are two other notable mention of php usage. Both are handling very high traffic loads ok (not spectacular), and I know that facebook is using a lot of C/C++ and some Java on the backend. The main reason that they are php is b/c it was the better choice for the founders, to do something quick at the time (2004-2005).
Ruby on Rails was not even out, and Python didn't have great and simple frameworks with simple learning curve.
So, at the time the two sensible choices were Java or. Php. A great question would be: If facebook or digg had to redo everything from the beginning, would have still chosen php?
PHP gives you more slack than any other language. . .
which is just enough rope to hang yourself with.
To be honest, part of it will depend on your style and part of it will depend on your discipline.
I'm a fan of Python. PHP is not my style. I like one way of doing things. I like namespaces. I don't like all the extra syntax that I feel is useless ({};$).
But that's just me personally. Many people hate python for those reasons - it's constraining.
Objectively, PHP allows you to do what you want easily. The only problem is that taking those shortcuts can come back to bite you later. If you appropriately use include(), make sure to template out design, and avoid some of those oh-so-irresistible hacky things, you'll be fine. Digg has done well with PHP.
The problem is that it's hard to know exactly where you're screwing up sometimes. For example, in python, every name used in a python source was defined either in that file or in one of the imports. That makes it trivial to figure out why that "I can't find that name" error is occurring. With PHP, that name could be meant to be included 10 files back. They simply all carry over.
So, is PHP bad? I personally think it is, but I'm a little conservative an authoritarian when it comes to programming rather than PHP's more loose style. Can PHP's style help you? Yes.
PHP is the VBScript of the open source world. It's available on almost every web host, and it seems to be what beginners learn first. While I'm sure it's possible to write things in a safe and mantainable way, most code examples you see will be from beginners and will have problems with the OWASP top 10. You can't look to the built in libraries for inspiration beacuse they're usually poorly designed.
Just because there have been success stories in a language (cold fusion and myspace, php and facebook) doesn't mean it's right for you. It took me one website and only 1000 lines of code to decide against PHP. If you've used it longer and like it, it's probably fine.
I currently do a lot of work in PHP, and although it isn't my favorite language to work with (braindead built-in library, for one), it's hard to argue with the results we get.
For the good of your soul, use a framework. We currently like Zend Framework, but I've heard good things about CakePHP and Symfony. If you stick with the framework and follow a sane MVC strategy you'll fix most of the problems you'll have using PHP as an HTML templating language.
I would recommend Zend Framework. I have had issues with Code Igniter. All the workarounds and unexpected stuff frustrated me - I think not only me but other users as well - that is why I think there is a fork: http://kohanaphp.org ... By the looks of it, I would recommend Kohana instead of Code Igniter. Either way, I am not so sure about the future of CI. That is why I choose Zend Framework.
The proper link to the KohanaPHP project is: http://kohanaphp.com. I've been using Kohana for the past few months and it is major improvement over other PHP MVC frameworks. It utilizes the OOP functionality in PHP5 to make structured PHP web development much easier and elegant. If you are looking for a new PHP framework, you should definitely consider Kohana. You could even integrate with Zend Framework classes if needed.
We do a lot of work in PHP, but wouldn't even consider it if it wasn't for clean MVC frameworks like Code Igniter.
To be honest, it doesn't feel much like PHP on the average bit of coding. It feels like a "real" language most of the time because of the framework. They have one of the best user guides I've ever run into (click Table of Contents at top):
http://codeigniter.com/user_guide/
I can second this. We use PHP along with a modern framework and love it. Deployment is easy and PHP is so widespread that you can count on a script existing to handle almost any little problem you face.
Granted there are times that its inconsistent library and lack of language features can become annoying. If we're discussing languages alone, PHP is certainly lacking.
With projects like mod_rails on the horizon and programmers trending away from PHP hopefully we soon won't need to choose between a solid language and super-simple deployment process.
i believe that every language has its perks, and PHP has quite a few. as far as back-ends go, there are a few types
-xml/json webservices
-low memory application servers(blogs, shopping sites, etc..)
-high memory application servers(data mining, indexing, processing, game servers)
i think php is a great low memory solution, when you get into higher memory loads for the app to process, you do not want to reload everything back in to ram for each request. php is single threaded per request, and as such you don't have access to sockets, or other event based activities on the server side.
i agree with the statement in general, that you should go with what you know to be the most efficient language for the task.
Having dealt with a lot of really awful PHP in my programming career (including some of my earlier stuff), it tends to unfairly taint my view of the language.
It's not terrible, but I've found that the clunky syntax for slightly more advanced stuff (e.g. anonymous blocks) really discourages some labor-saving and repetition-avoiding coding practices that a language like Ruby encourages.
It's a really good fit for small-scale sites with well-defined requirements. But it requires some well-thought-out conventions to scale well, the sort of stuff you can't come up with unless you've done it wrong a couple of times yourself. Unless you borrow someone else's work by using one of the frameworks out there.
Go for the framework that lets you develop quicker. The truth is that there's no framework on earth that has solved the 'scaling' problem for you. Anyone who says '<framework x> doesn't scale' in all probability has never scaled anything.
Scaling isn't even a real, real problem you need to worry about until you're a top 1000 site at minimum, or > 10MM page views a day. At numbers past that, no framework is going to magically solve your database partitioning problems.
PHP simply requires discipline, which unfortunately many people in the PHP world lack due to its initial target audience. Provided you find real hackers and not just designer-turned-coder types, PHP is totally workable.
Mind you, when you're getting into the more functional side of Ruby or Python, PHP starts to show its limits as a language. But it's still fast to code in and to do so well if you know what you're doing.
PHP is my preference for web development. However, you can do anything with any language. The part that has the most influence on how easy or hard it is usually the framework, not the language.
On that note, I am tired of articles comparing PHP to Rails. It's like comparing a Honda to the metal used to build another car.
i've been using it for all of my websites for about 6 years. It's robust enough to do just about anything. it's just close enough to see C to be familiar and just different enough to slightly irk you. I'm getting to ready to roll out my first Ruby site though.
I used PHP heavily for a few years (~70% PHP, 20% perl, 10% Java), and enjoyed it for awhile. However, it seems like it is impossible to create clean and well-divided code in PHP. This weighed on me heavily, as I had two 10,000 line projects that I was the sole maintainer for. Even if you managed to create well-structured code, it was always very... ugly (too many unnecessary symbols $, ->, etc). It wasn't much fun to work in every day.
I'm using Ruby now and I would never go back.
Here's my rough order of language preference for server-side languages that I have experience in:
Ruby > Python > C# > PHP > Perl > Visual Basic > Java > C
It's a fine backend language for a small to medium sized website, but you need to be aware that at a certain size (in terms of complexity of the application you are building) you'll often find yourself fighting against the language. That's not to say you can't build large applications in PHP, just that you need a great deal of discipline to do so. You'll either need to adopt one of the MVC frameworks (Symfony for example) or roll your own. A lot of the features in the framework you chose will be workarounds for limitations in PHP itself (such as its lack of decent namespacing and poorly designed database access primitives).
Out of curiosity could you give an example of a language where this isn't the case? As far as requiring a framework of sorts when dealing with large sized/complex websites?
I'm not sure if this is a troll question. Elaborate on why you are asking. You are asking: "what do you think of pudding" instead of "hey, I'm having a dinner party and can't decide between apple pie and pudding, help me!"
Well, we have used PHP extensively until now. We have gotten more disciplined in designing code, compartmentalizing it into classes, documenting the code etc.
However, I recently read an article on YC about how many startups go through a phase debating about which language an application should be built on. We did not give this much thought as we saw a few prominent websites like facebook use PHP and we thought PHP seemed to be a pretty scalable language. Plus, with support for OOP (as of PHP 5), PHP seemed to be a pretty good choice.
I am interested in evaluating if we made the right decision
I build absolutely everything on the top of PHP and the WACT framework. The latter ensures that my code stays maintainable and well-organized. It also emphasizes the use of design patterns. I'd never switch to anything else when it comes to web development and I'd have left the industry if there was no WACT. That's why I became one of its core contributors.
I use PHP for basic stuff where I don't care much about performance or anyone else maintaining it. It's installed on pretty much every web host and it's easy enough to whip stuff up in. I haven't done a big web site in a long time, but I can't imagine using anything other than Python for it.
Bottom line is: PHP can get the job done (cheap and fast) and scales pretty well. I have been using Zend Framework for almost a year now - with the release of 1.5, I recommend it above anything else (other PHP MVC Framework).
It's a significantly better programming language; I don't think you'll be able to find anyone who knows both PHP and Python and will disagree with that statement. PHP is a very simple language with built-in features for web application development. Python is an advanced, multi-paradigm general purpose language that has evolved over more than a decade.
Here are a few Python language features that I seriously miss when I'm working in PHP:
- Modules and namespaces! This is the feature that initially drove me away from PHP.
- List comprehensions (let you construct a new list based on an old list in a one-liner)
- Built in iterator support (easy "for item in collection" support for many different types of collection)
- First class functions and closures (so you can treat your functions as data)
Those are just four off the top of my head. If you haven't looked at Python before (but already know how to program) I suggest taking a look at http://diveintopython.org/ which is a free online book.
But, PHP5's iterator is broken. The only way you can use it is in a foreach loop. In Python, iterators can be used with any iterative construct.
Namespace support in PHP never really bothered me, but I've occasionally run into problems with name clashes with built in functions. It'll be welcomed anyway for sure.
I'll admit, I'm a rookie. I've spent a few months now learning and writing PHP...is my effort in vain? Should I ditch PHP and dive into Ruby with a Rails framework?
I don't think your effort's in vain. If you like it, keep at it. When you feel confident in your knowledge on the language, you can then choose to move on and experiment with other things. Same for any language, really.
Myself, I'm just now getting started into Ruby on Rails. I finally figured out a project to get me interested in learning the Rails part of it. I just need to get cracking.
amrithk, what type of website are you thinking of building ? Your question gives me as little clue as, "what language should I use to write software???
Its been informative learning about your experiences. What do you mean by frameworks? Something like a backend scripting language, a templating tool (like Smarty or PHPTal), etc?
I think he means MVC (Model-View-Controller) Frameworks. These things are so hot nowadays... If your site is structured well, then you wouldn't have to use templating engines like Smarty (god these things are so annoying)...
Don't let the scaling police and architecture astronauts fool you: with the right architecture in place (i.e. a framework like Cake or Zend) and a smart scaling strategy (opcode caching, object caching, page caching, etc), PHP is a great choice for web applications.
Sure PHP has a low barrier to entry, which can lead to poor coding practices, but that shouldn't be a reason for people to express an absolute hate for it. Rather, it's important to stress continual education regardless of which programming language you choose.