(原题目:Last we checked, PHP is a framework. By Akash Mehta. June 8th, 2008 ) When it comes to web programming languages, PHP probably holds the record for copping criticism from the community at large. Comparisons with alternatives such a
(原题目:"Last we checked, PHP is a framework". By Akash Mehta. June 8th, 2008 )
PHP is designed for the web. You could plug vanilla Ruby or Python into a web server and get up and running pretty quickly. But, at least at a basic level, you’d want a framework to deal with common issues of web development. In PHP, you just get started. PHP and Apache work out request data, output handling and more, right out of the box. (PHP also masters deployment.) David Heinemeier Hanson, the creator of the Ruby on Rails framework, calls this the immediacy of PHP.
PHP就是为web而设计的。用户也可以把纯粹的Ruby和Python应用放在web服务器里并可以运行得很好。但是,至少在基础水平 上,用户还是希望使用框架来处理那些通常web开发会遇到的问题。使用PHP时,只要你动手就行了。PHP和Apache会在内部来处理需要的数据,输出 处理等问题。Ruby on Rails 框架的创造人David Heinemeier Hanson形容其为PHP的直接性。
Now, consider the “average” PHP frameworks. They help you handle request data, manage your output, control app flow - essentially, extending PHP’s inbuilt functionality. They are, therefore, PHP frameworks on the PHP framework. PHP provides a vast array (pardon the pun) of functionality out of the box. But when you want to do things your way, it gets out of the way, and this is really important when building anything beyond a simple database frontend.
How many PHP applications in wide distribution are built on a third-party framework? MediaWiki? No framework here. Wordpress? Not here either. Drupal? You get the idea. Each of these applications have their own framework, inasfar that the developers built a structure for their code that suited what they were trying to create. These three, and the countless others, clearly did something right - MediaWiki even powers one of the world’s top 10 websites. And when building these “frameworks”, PHP helped them along the way.
有多少广泛分布的PHP应用是建立在第三方的公用框架上的呢?MediaWiki? 没用这些框架。Wordpress? 也没用这些框架。Drupal又如何? 看到这里,你应该明白了。这里的每个应用都有它们自己的框架,在这里开发者为他们的应用量身订造出合适的结构。这三个应用,联同其它无数的应用一样,做得 正确无误 -- MediaWiki网甚至成为了世界10个顶级网站之一。在建造这些"框架"时,PHP顺其自然地做了自己的事情。
Sure, Cake, Symfony, CI - they all help you build PHP applications. But unlike a Ruby framework or a Python framework, coding is perfectly tolerable without them. Of course, most developers tend to create their own framework as they go along - I call this PHP’s DIY framework mentality, where you build the last level in your stack, and by extension you know exactly what’s going on under the hood.
没错,Cake, Symfony, CI(Codelgniter) -- 都可以帮你开发PHP应用。但和使用Ruby框架或Python框架不一样的是,即使不用这些PHP框架,程序一样地好写。当然了,很多开发者都倾向于创 造自己的框架 -- 精神上我称之为PHP的自做框架,在那可以根据自己的需要来开发,并扩展自己最清楚的内部系统功能。
This comes back to the oft-cited “best tool for the job” argument - but by being a “half framework” of sorts, PHP simply helps you within a web context. I’m sure Rails is great for countless applications; Ruby syntax helps a little too. But beyond the basics, the language becomes increasingly irrelevant, and a framework will force you to build your app according to design decisions made by the original developers. On the other hand, PHP allows you to quickly put together your application the way you want, helping you with the web-based aspect, and without having to break the language/framework to achieve your goals. Essentially, PHP is the web layer without the framework baggage.
Twitter recently had some downtime that could be attributed to its use of Ruby on Rails. Now, there’s nothing wrong with Ruby, or Rails. But Twitter is a messaging system, RoR is an application framework. Could Rails be worked around to suit Twitter? Maybe. Could Twitter have avoided these problems if they’d used PHP? Probably. Twitter’s developers have noted they weren’t quite expecting the site to be so succesful. If they had built it in PHP, they would probably have encountered other (similar) problems earlier on, rewritten the entire app while it was still feasible, and built a powerful system that could scale just fine (likely with the messaging platform in C). Using PHP could have helped, not as a language with syntax and libraries as such, but as a web development platform that gives developers the freedom to architect their systems as they want. (They could also have tried Erlang.)
So the next time you’re on the lookout for a PHP framework to build your killer app on, consider using the best framework of them all: PHP. It will give you the freedom to achieve what you want, how you want, with results. A quick hack? Check the manual, it could be a one-liner. A massive distributed messaging platform? Full steam ahead, build it your way. For everything in between, there’s a multitude of options, but if you have the time, PHP is all the framework you need.