使用Java还是PHP构建网站(原文http://www.coderanch.com/t/569239/java/java/Java-PHP-Building-Websites)

PHP的好处:

----- 

API简单:PHP的API比java更直观,开发效率更高

Simpler API: PHP's API is much more intuitive than java. Takes less time to get productive with PHP than with Java 


PHP was not a resource hog: This is more relevant to the situation 9-10 years ago, than it is today. But the damage was already done. PHP did not need as much memory or as much processor power as a java web app running in a JVM. So PHP was more suitable to commodity hardware in those days. 9 to 10 years ago, I was told about JSP developer experiences, where people would write JSP and then go have a cup of tea for half an hour while the compiler compiled and server deployed it. Then even the simplest JSP requests would take another 30 seconds to couple of minutes. JVMs became much more performant only later on. Performance is much better nowadays of course, but even now, a request to a java web app requires more memory than one to a PHP app. 

PHP所消耗的资源不多:相较今天,这个优势在9-10年前更明显。与运行在java虚机上的web应用相比,PHP所需的内存或CPU电耗较少。那时候,PHP可以在更多的硬件上运行。9、10年前,我听说JSP开发人员常常有这样的经历:写完一段JSP后可以喝上半个小时的茶以等待编译和部署。即使今天,一个最简单的JSP请求也要花上30秒到几分钟的时间。直到最近JVM效率才有显著提高。不过,即使现在,一个java web应用的请求也需要更多的内存。


Less typing. Faster to write code: PHP was a procedural language that later got OOP extensions. So global functions are still common in PHP. Makes for less typing. 

The untyped nature of language too makes for less typing. 

输入简单:编代码更快。PHP以前是过程语言,后来才作了OOP扩展。所以全局函数在PHP中仍然非常普遍。带来的好处是所需编写的代码量更少。PHP语言的无类型特性减少了输入量

PHP is not strongly typed while java is. This is both a boon and a bane. It's a boon because you have to do less typing. 
But it's a bane - specially in large projects - because one developer will have no idea what data is being passed by another component unless it's documented well. 

This is not so much of a problem when single developer is developing and uses some common sense coding conventions. 

PHP不是强类型定义,java是强类型定义。这既是好事又是坏事。好处是减少输入,坏处是开发人员常常不清楚从另一个部件过来的数据到底是什么,除非文档化做得很好。这在开发大型项目时尤其明显。


Had open source server support much earlier than java (I believe this was one of the main reasons for its popularity): Apache - 1995 I think. Apache Tomcat - 1999. 

开源的PHP服务器出现得更早。Apache -1995就有了。Apache Tomcat - 1999


Arrived much earlier on the scene than JSP (I believe this was one of the main reasons for its popularity): PHP - 1995; JSP - 1999 

比JSP出现更早。


Easier for web designers to pick up: PHP is easier for web designers to pick up, I believe this is another main reason it got traction 

web设计人员更容易上手


No installation complications: PHP interpreter usually comes bundled with Apache in most installation packages. Java on the other hand requires JRE to be installed. 

安装简单:大多数安装包将PHP 解释器与Apache捆绑在一起。而Java需要额外装JRE


Development cycles take less time: Changes can be made to a PHP file and these changes can be seen immediately on a refresh. This is due to PHP's shared-nothing architecture. PHP has no concept of shared memory, unlike java's static data and session data which remain in memory between requests. Once a PHP request is finished, all data created on the heap is deallocated. PHP session data is saved on file by default, but can be saved to DB. 

In java web development, on the other hand, the only way to make a JSP change or java servlet change active is to rebuild the war and redeploy the web application, thus making it much less nimble than PHP. Of course, some commercial tools like JRebel make this easier, but it's still not as nimble as PHP. 

开发周期短:对PHP的修改基本是所改即所得。这由PHP的无碎片架构决定。PHP不像java的静态数据和session数据需要在不同请求间保留数据。一旦pHP请求建树,所有分配的堆数据都被释放。PHP的session数据缺省存放在文件中,但也可存在DB内


More hosting options: I agree with Stephen's point. It's much easier and cheaper to host PHP websites than it is to host Java websites. 

有更多的主机host选择:host PHP站点比host java站点更容易也更便宜


Cons: 

缺点:

------ 
Not good support for DB transactions: DB transactions are by nature complex. Java has extremely good standardised APIs for transactions (JDBC) and for distributed transactions(JTA). 
PHP on the other hand had no such support. Even now, some DB agnostic APIs are available - like PDO - but I don't think transaction support is any better. 

数据库的事物处理支持不好:数据库的事物处理是很复杂的。java有JDBC和用于分布系统的JTA这样的非常强大的事物处理标准API


No multithreading: PHP has no native threading API. The runtime is also said to be not threadsafe (there's lots of heated debate about this depending on whether the poster is a PHP fanboy or not). I have not done any detailed analysis, so my knowledge is borrowed. But what I understand is some PHP extensions (these are the adapter plugins that add functionality to the PHP interpreter) are thread unsafe, and since nobody seems to know exactly which ones aren't, it's risky to use threading. 
没有多线程支持:PHP没有本地线程API。runtime据说也不是线程安全(这点争议很大)

No asynchronous processing support: Because there's no multithreading support in PHP. This is a strong point of java, making java a good candidate to deploy in the services (business logic) layer when some heavy backend processing is involved. It's possible to deploy webdesigner friendly PHP in the web tier and deploy scalable java (or other JVM language) in the business logic tier - and then integrate them through web services. 
没有异步处理机制:由于没有多线程支持。这是java的强势,如果web应用需要复杂的后端处理,那么java是一个部署在业务逻辑层上的好选择

Linkedin uses java extensively. Twitter uses Scala (a JVM language) for its backend. Any site based on Liferay CMS or Alfresco CMS (they're called "portal"s in java world but are comparable to the CMSes of PHP world, like wordpress and joomla) is running on a java stack.

LinkedIn站点大量使用java. Twitter使用Scala( 一种JVM语言)作为它的后端。任何基于Liferay CMS or Alfresco CMS(在java世界中他们称作portal,在php中称为CMS,就像wordpress和 joomia)的站点运行于java栈

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值