oracle Java 或 PHP 服务器端 Web 应用程序以及为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3970290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java OR PHP Server Side Web App and Why?
提问by Chris
I am creating a web app that involves a lot of DB access and parsing and analysing data , Java is the language i am most comfortable with but recently have been told that I should consider to use PHP as it makes DB access protocols a lot simpler.
我正在创建一个 Web 应用程序,它涉及大量的 DB 访问以及解析和分析数据,Java 是我最熟悉的语言,但最近有人告诉我应该考虑使用 PHP,因为它使 DB 访问协议变得更加简单。
I dont have any great knowledge of PHP but would be willing to learn for use if it was going to be the better option as far as functionality , portability ect is concerned.
我对 PHP 没有任何深入的了解,但如果它在功能、可移植性等方面成为更好的选择,我愿意学习使用。
The Web app will run against an Oracle DB and use Flex for the GUI, Please any experiences of similar projects and what made your chosen approach better would help or just opinions of any sort.
Web 应用程序将针对 Oracle DB 运行并使用 Flex 作为 GUI,请提供类似项目的任何经验以及使您选择的方法更好的方法将有所帮助或只是任何形式的意见。
回答by Pekka
If you're comfortable with Java, I don't see the need to learn/use PHP. There is nothing that PHP can do that Java can't.
如果您熟悉 Java,我认为没有必要学习/使用 PHP。没有什么是 PHP 做不到的,而 Java 做不到的。
It's true that by and large, PHP is a much more permissive language, and some tasks can be fulfilled more quickly and with less code. PHP certainly has less built-in abstraction than Java has. But if you're comfortable with Java, I'd say stick with it.
确实,总的来说,PHP 是一种更为宽松的语言,并且可以更快地完成某些任务并使用更少的代码。PHP 的内置抽象肯定比 Java 少。但是,如果您对 Java 感到满意,我会说坚持使用它。
(I'm saying this as a PHP developer.)
(我是作为 PHP 开发人员这么说的。)
回答by Paulo Scardine
IMHO if you know java, use JPA.
恕我直言,如果您了解 Java,请使用 JPA。
If you want to learn something new and fast prototyping, use python/django.
如果你想学习一些新的和快速的原型设计,使用 python/django。
回答by symcbean
There is a huge amount of difference between the syntax, phuilosophy and implementation of the 2 languages. I would suggest that "makes DB access protocols a lot simpler" is not a particularly good reason in isolation for choosing one language over another.
两种语言的语法、哲学和实现之间存在巨大差异。我建议“使数据库访问协议更简单”并不是单独选择一种语言而不是另一种语言的特别好的理由。
My background is as a PHP programmer, but I currently support several large Java web applications. If you were starting from the same point with both languages then I'd definitely favour PHP over Java - but a full discussion of the reasons why would take a lot more time and space than are available here. However if you already have strong Java skills, then you have to weigh up the costs of acquiring the right level of skill in PHP - due to the differences in the way these systems work, you're going to find your knowledge of Java as much of a hindrance as a benefit in achieving proficiency in PHP.
我的背景是 PHP 程序员,但我目前支持多个大型 Java Web 应用程序。如果您从同一点开始使用两种语言,那么我肯定会更喜欢 PHP,而不是 Java - 但要全面讨论为什么会比此处提供的时间和空间多得多的原因。但是,如果您已经拥有强大的 Java 技能,那么您必须权衡获得适当水平的 PHP 技能的成本 - 由于这些系统工作方式的差异,您将同样发现自己的 Java 知识作为提高 PHP 熟练度的好处的障碍。
Other factors I would suggest you have a look at are:
我建议您查看的其他因素是:
1) architecture - PHP requires far better understanding of the underlying protocols than Java (where a lot of functionality is provided by libs/ frameworks)
1) 架构 - PHP 需要比 Java 更好地理解底层协议(很多功能由库/框架提供)
2) ease of deployment
2) 易于部署
3) performance considerations - using an opcode cache means the difference between simple programs written in Java and PHP is small, since the former are usually written inside very complex frameworks, PHP can often have the edge. It certainly does not have the same complexity for memory mngmnt
3) 性能考虑——使用操作码缓存意味着用 Java 和 PHP 编写的简单程序之间的差异很小,因为前者通常是在非常复杂的框架中编写的,因此 PHP 往往具有优势。它当然没有内存管理的相同复杂性
4) TCO - PHPs ease of use is a double edged sword - you need to know a lot about Java just to get a program running, but the world and his dog think they can write good code in PHP. IME its more difficult to find competent PHP programmers than Java programmers.
4) TCO——PHP 的易用性是一把双刃剑——你需要了解很多 Java 才能让程序运行,但世界和他的狗认为他们可以用 PHP 编写好的代码。IME 比 Java 程序员更难找到称职的 PHP 程序员。
回答by dudewad
For me this comes down to performance. When you look at PHP it has certainly been deployed on extremely large platforms (Facebook used it almost exclusively at the beginning), but in general it is used on smaller platforms. Java, for me, when you look at it's scalability benefits is superior, but only when you know you're going to be scaling.
对我来说,这归结为性能。当您查看 PHP 时,它肯定已部署在非常大的平台上(Facebook 一开始几乎只使用它),但通常它用于较小的平台。Java,对我来说,当你看到它的可扩展性优势时,它是优越的,但只有当你知道你将要扩展时。
Understanding the underlying life cycle of a request is very important. That is, knowing what a Java container is and how a Tomcat server runs helped me understand tremendously the performance implications.
了解请求的底层生命周期非常重要。也就是说,了解 Java 容器是什么以及 Tomcat 服务器如何运行有助于我极大地理解性能影响。
Don't try to choose one over the other over single attributes such as "ease of coding" or "database connectivity"- they are different enough that by focusing on just a couple of "important" things you'll be essentially selecting based off of biased information. That is, PHP makes it easier to connect to a DB if you look at them on a surface level- "Ugh! I have to install a JDBC, wtf is that???", etc- but that's the lazy man's excuse. There is nothing Java can't do that PHP can (that I'm aware of).
不要试图在单一属性上选择一个而不是另一个属性,例如“易于编码”或“数据库连接性”——它们已经足够不同了,通过只关注几个“重要”的事情,你基本上会根据的偏见信息。也就是说,如果您从表面上查看它们,PHP 可以更轻松地连接到数据库 - “啊!我必须安装 JDBC,wtf 是那个???”等等 - 但这是懒惰人的借口。没有什么是 Java 不能做的,而 PHP 可以做到的(我知道)。
For me the question is how do you realistically(Read: realistically) see your application working- do you plan on getting thousands of visits per hour or are you talking a hundred hits a day like the grand majority of the little projects out there?
对我来说,问题是你如何真实地(阅读:真实地)看到你的应用程序工作 - 你计划每小时获得数千次访问,还是像大多数小项目一样每天谈论一百次点击?
The benefits of PHP on smaller projects, particularly for the programmer that doesn't fully grasp OOP architecture are enormous- but don't get lazy and just take PHP because it's easier out of the box. Java is extremely powerful and simply by learning it can teach you more than you realized you didn't know about OOP and good programming practices in general (if you come from the self-taught realm like I do).
PHP 在较小的项目中的好处,特别是对于没有完全掌握 OOP 架构的程序员来说是巨大的 - 但不要偷懒,直接使用 PHP,因为它更容易开箱即用。Java 非常强大,通过学习它可以教给你的东西比你意识到的你不知道的关于 OOP 和良好的编程实践要多得多(如果你像我一样来自自学领域)。
Basically, I'd say analyze your estimated project load plus ramp-up time if you have to learn one or the other, gauge your efficiency and scalability requirements, keep asking questions, and then decide which platform is better.
基本上,如果您必须学习其中一个,我会说分析您估计的项目负载和启动时间,衡量您的效率和可扩展性要求,不断提出问题,然后决定哪个平台更好。
Hope that helps....!
希望有帮助....!
回答by Comic Sans
PHP lets you do a lot of web things with less effort and fewer lines of code than Java does, I think (and I'm only talking about my own experience - there are always some who tell you "Use Java, PHP is crap" and there will be the ones to tell you "PHP is so much better than Java". Don't listen to us, simply try it or you will never know!). I do a lot of Java stuff, but as far as web apps are concerned, I'm not happy with it. For most of our customers, it's not possible to use Java, too, so I don't have that much of a choice, anyway.
PHP 可以让你以比 Java 更少的努力和更少的代码行数做很多网络事情,我想(我只是在谈论我自己的经验 - 总是有人告诉你“使用 Java,PHP 是垃圾”并且会有人告诉你“PHP 比 Java 好得多”。不要听我们的,简单地尝试一下,否则你永远不会知道!)。我做了很多 Java 东西,但就网络应用程序而言,我对此并不满意。对于我们的大多数客户来说,也不可能使用 Java,所以无论如何我没有那么多选择。
There are some good PHP frameworks out there (Yii for example, which I like most) and really good orms as doctrine or active record. If you have to learn the language and are interested in agile development, also think about Ruby (Ruby on Rails) or Python (Django) as these are the cool kids in town :)
有一些很好的 PHP 框架(例如 Yii,我最喜欢它)和非常好的 orms 作为学说或活动记录。如果您必须学习这门语言并对敏捷开发感兴趣,还可以考虑 Ruby (Ruby on Rails) 或 Python (Django),因为这些都是镇上的酷孩子:)
回答by Brent Baisley
Why not use both? Quercus will run PHP in Java. You can call Java code as if it was native PHP functions. You get the best of both. And your PHP will actually run faster than under Apache.
为什么不同时使用?Quercus 将在 Java 中运行 PHP。您可以像调用原生 PHP 函数一样调用 Java 代码。你可以两全其美。并且您的 PHP 实际上会比在 Apache 下运行得更快。
I'm a PHP programmer, and while PHP DB access protocols may be "simpler" (debatable), I wouldn't say they are better. Java can use DB connection pooling and can "persist" data, code and objects.
我是一名 PHP 程序员,虽然 PHP DB 访问协议可能“更简单”(有争议),但我不会说它们更好。Java 可以使用数据库连接池并且可以“持久化”数据、代码和对象。
回答by jcalvert
Well, the real issue here is that you need libraries to make your work easier. JVM as a platform has many more options than PHP, if for no other reason than you can hybridize your application with embedded languages. Also, Hibernate is fantastic as an ORM (Object Relational Mapping), basically taking your tables and looking at them as POJOs.
好吧,这里真正的问题是您需要库来使您的工作更轻松。JVM 作为一个平台比 PHP 有更多的选择,如果没有其他原因,你可以将你的应用程序与嵌入式语言混合。此外,Hibernate 作为 ORM(对象关系映射)非常棒,基本上将您的表视为 POJO。
If you're doing lots of 'raw' stuff, I actually like using Sequel, which is a Ruby library and works very well on JRuby. In general, I find that the duck-typing/concise code that people like about PHP is absolutely replicable in Ruby via JRuby (or Jython for you Python enthusiast types).
如果你正在做很多“原始”的东西,我实际上喜欢使用 Sequel,它是一个 Ruby 库并且在 JRuby 上运行良好。总的来说,我发现人们喜欢的关于 PHP 的鸭式/简洁代码完全可以通过 JRuby(或 Jython 为您的 Python 爱好者类型)在 Ruby 中复制。
The best library is going to be dictated by the funkiness of the schema you're dealing with, in addition to the type of work you're doing. Do you need to do lots of complicated queries, fetching columns from several tables all at once? Or is it more along the lines of "I Need to fetch all the Orders for a certain customer and display it in an order history chart"? ORMs are better suited to the latter, which is what web apps tend to be, but your mention of parsing and analyzing makes me wonder if it's more the former.
除了您正在做的工作类型之外,最好的库还取决于您正在处理的模式的时髦程度。您是否需要进行大量复杂的查询,同时从多个表中获取列?或者更像是“我需要获取某个客户的所有订单并将其显示在订单历史图表中”?ORM 更适合后者,这就是 Web 应用程序的倾向,但是您提到的解析和分析让我想知道它是否更适合前者。
Hibernate gives you the greatest flexibility, I find. It's not a good idea to use autogenerated stuff without reviewing it, but if you use Eclipse, there's a plugin that will generate the classes for you.
我发现 Hibernate 为您提供了最大的灵活性。不检查就使用自动生成的东西不是一个好主意,但是如果您使用 Eclipse,有一个插件可以为您生成类。
Another reason to go with Java: If you look at the Glassfish container for your web application, it has built in JDBC pools for you and you can look at the statistics and management of the pool. If you have a lot of database access, this could be pretty useful.
使用 Java 的另一个原因:如果您查看 Web 应用程序的 Glassfish 容器,它为您内置了 JDBC 池,您可以查看池的统计信息和管理。如果您有很多数据库访问权限,这可能非常有用。
回答by user480743
I think there is no need for PHP , you can just go with Java.If you consider that application to be a web application then you can use PHP.So you can access it from anywhere
我认为不需要 PHP ,您可以使用 Java。如果您认为该应用程序是 Web 应用程序,那么您可以使用 PHP。因此您可以从任何地方访问它