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

zz/2024/4/19 22:53:38

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栈


http://www.ngui.cc/zz/2700299.html

相关文章

tars-php 改造 invoke 支持多个tcp请求

现在“微服务”越来越少流行, 公司内部很多接口原来是CGI, 或者直接读DB,都改成用微服务接口, 不用CGI接口,其实挻好的,不好暴露接口到公网,网络延时也少,不需要做鉴权,直…

golang []map[string][string] , 先按大小,再按键名排序

type IpSortItem struct {Value int json:"value"Name string json:"name" } // 先按数量排序,再按名称排序 func sortIPView(rspData []map[string]string) []*IpSortItem {var totalList []intdataList : make(map[int][]string)for _, …

Java eclipse 设置代码折叠

1 windows->perferences->General->Editors->Structured Text Editors 选中Enable folding 效果 2 windows->perferences->Java->Editors->Folding 效果

javac 命令找不到

环境配置出错 仔细的查看每一个配置 复制黏贴的还是出现错误 在自己的电脑中生成的时候错误 仔细查看对比就可以了 使用命令也可以 set java_homeC:\Program Files\Java\jdk1.6.0_26 安装JDK的根目录 set classpath%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar; …

thinkPHP安装与配置

使用Git安装thinkPHP: 1 git clone https://gitee.com/liu21st/thinkphp5.git tp5 ; clone thinkPHP的基础框架 ,tp5为文件名字。 2 切换到tp5目录下在命令行中使用 3 git clone https://gitee.com/liu21st/framework.git thinkphp 4 git checko…

多线程同步I/O和单线程异步I/O

多线程同步I/O和单线程异步I/O 2014-08-24 同步I/O与异步I/O 线程在执行中如果遇到磁盘读写或网络通信(统称IO操作),通常要耗费较长的时间,这时OS会剥夺此线程的CPU控制权,使其暂停执行,同时将资源让给其…

nodejs 调试技巧

1, 命令行调试 run 执行脚本,在第一行暂停 restart 重新执行脚本 cont, c 继续执行,直到遇到下一个断点 next, n 单步执行 step, s 单步执行并进入函数 out, o 从函数中步出 setBreakpoint(), sb() 在当前行设置断点 setBreakpoint(‘f()’), sb(...) 在函数f的第一…

Zookeeper实战之单机集群模式

Zookeeper的单机模式的安装及应用,但是Zookeeper是为了解决分布式应用场景的,所以通常都会运行在集群模式下。由于手头机器不足,所以打算在一台机器上部署三个Zookeeper服务来组成一个Zookeeper集群。这里解压Zookeeper的安装包到/opt目录下&…

ubuntu系统查找命令

ubuntu系统查找命令 一.以文件名查找: 1. find 命令 find / -name "filename" 目的:在根目录“/”开始搜被称为filename的文件,“filename”文件名可以包含通配符(*,?)&#xff0…

kudu 文件描述符 更改

kudu 文件描述符超过阀值 kudu 文件描述符缺省打开文件数为32768 在/etc/security/limits.d/下找到了cloudera的limit配置文件,里面限制为32768 /etc/security/limits.d/cloudera-scm.conf 修改: 32768会覆盖系统配置,cm启动的进程最大打…