FAQ
在线手册:中文  英文

PHP 和其它语言

PHP 是 web 编程最好的语言,但其它语言怎样呢?

  1. PHP 对 ASP?
  2. PHP 对 Cold Fusion?
  3. PHP 对 Perl?
PHP 对 ASP?

ASP 本身并不真的是一种语言,它是 Active Server Pages 的缩写,实际上用来进行 ASP 编程的语言是 Visual Basic Script 或者 JScript。ASP 最大的缺点是它是一个专有系统而只能在 Microsoft Internet Information Server(IIS)上使用。这限制了它只能在基于 Win32 的服务器上使用。有几项进行中的计划使 ASP 可以在其它环境和 web 服务器中使用: » Halcyon(商业的)的 » InstantASP» Chili!Soft(商业的) 的 Chili!Soft ASP和» Mono (open-source)。ASP 被认为比 PHP 慢和麻烦,也不稳定。一些 ASP 的正面观点是既然它基本上用 VBScript,那如果你已经懂得用 Visual Basic 编程就会相对容易拾起这种语言。在 IIS 服务器中默认激活了 ASP 支持,这使它容易启动和运行。ASP 中内置的组件实在是很有限,因此如果需要一些“高级的”特点例如与 FTP 服务器交互,需要购买额外的组件。

PHP 对 Cold Fusion?

PHP 普遍被认为对复杂的编程任务更快和更有效以及勇于尝试新主意。PHP 也通常被提及更稳定以及占用更少资源。Cold Fusion 具有更好的错误处理,数据库抽象和数据解析,尽管数据库抽象已经在 PHP 4 中解决了。另外一个被作为 Cold Fusion 的强项列出来的是它卓越的搜索引擎,但也被指出搜索引擎不是 web 脚本语言中应该包括的东西。PHP 可以在几乎每一个现有的平台下运行;Cold Fusion 只能在 Win32,Solaris,Linux 和 HP/UX 下运行。Cold Fusion 有很好的集成开发环境以及通常更容易上手,反之 PHP 则一开头就需要更多的编程知识。Cold Fusion 是为非程序员的头脑所设计,而 PHP 则聚焦于程序员。

PHP 对 Perl?

PHP 对 Perl 最大的优势就是 PHP 是为 web 脚本设计的而 Perl 则被设计用来做更多的事也因此而非常复杂。Perl 的灵活性/复杂性使得用它能很容易写出代码但却让另一个作者/编程者非常难读懂。PHP 则不容易把人搞糊涂以及具有更严谨的格式同时也不失灵活性。PHP 比 Perl 更容易集成进现有的 HTML 中去。PHP 具有差不多所有 Perl 的“好”功能:结构,语法等等,但却没有使它达到 Perl 的费解程度。Perl 是一种久经考验真正的语言,从上个世纪八十年代末起就到处都有,但是 PHP 成熟得非常快。


FAQ
在线手册:中文  英文

用户评论:

cs dot abdullah at hotmail dot com (2010-11-05 03:57:10)

I have taken ZCE (Zend Certified Engineer) before couple of years and I am working in the field of Compiler Construction. However, from my opinion PHP is the best language that is used to design web solution because it extendable language. As a programmer in C, I found PHP internally as easy as externally.
PHP is the best ever !.

steve at caralan dot com (2009-08-09 04:25:57)

Comparison of programming languages is a pretty spurious exercise, but here goes:
I have programmed with Perl for many years and have yet to find anything I want to do that Perl can't deliver. It is justifiably described as the "Swiss Army Chainsaw" of programming.
I am much less experienced with PHP but have found it to be relatively lightweight. PHP isn't Perl.
However, in my opinion PHP is much easier to work with and does what it's designed to do more elegantly than Perl. PHP is usually the best option within the areas where PHP is designed to excel.
I wouldn't want to be without either tool. Having both is the best solution.

tony (2008-04-16 13:01:08)

The paragraph on "Cold Fusion" (it's actually "ColdFusion", by the way), and in the included link is so woefully inaccurate and out of date, that it's not even funny.
I'm not going to debate the the pros and cons of each language, but PLEASE -- let people be informed by information that's more based in reality.

fabioissamu at yahoo dot com (2007-02-21 11:48:21)

Tim Bray, who - among many other things - co-edited the XML 1.0 and XML namespace definitions, was invited to the International PHP Conference to give a keynote about "How to combine PHP technology with Java based on Enterprise Systems". I had the pleasure to talk with him and I like his spirit. During his keynote, he presented some very interesting comparison between the popular development "frameworks" PHP, Ruby on Rails (RoR, Rails) and Java
http://www.tbray.org/talks/php.de.pdf
in that he show PHP the first in scalability

bb at servertje dot nl (2006-06-06 04:58:58)

I think it's worth to mention that it's incredible easy to write a PHP module in C and use it in your scripts with the speed of true machine language. All the PHP API functions are there and there's plenty of examples due to the many existing modules and their source codes.
The advantage here is programming the relative simple business logic in PHP and programming those core functions that really require speed in PHP modules, if you really have to.
Compiled Java classes act more like optimised / confuscated scripts and still needs an interpreter in the end.
The only disadvantage about PHP is the somewhat quirky language and inconsistant (and long) function names, which makes it hard for newbies to learn from scratch.

good dot midget at gmail dot com (2005-12-16 14:49:57)

I think there's been a slight overlook within the comments about PHP's model for OOP.
Firstly, I was absolutely thrilled to see the enhancements of PHP5. I've been using PHP for... gees... a long time now. But what's always been lacking has been fully implemented OOP. Now, granted, there are ways to do things like method overloading, but c`mon.... really... Now, I know the argument is that PHP is related to the web - not application development. I believe that the PHP community today suffers from this mentality. The fact of the matter is that the world is rapidly shifting towards an SOA mentality, and rich applications presented through the web. In light of this PHP should be regarded as valuable tool for application development.
I would say that while PHP has tremendous strength, it equally lacks in its implementation of OOP requirements. I find that most suggested "design patterns" are weak workarounds in PHP. C# (.NET), Java -- hell even ActionScript have a fully OO implementation allowing effective implementation of recognized design patterns. Futhermore, due to PHP's lack of OO support, true collaborative team development is greatly hindered. This is particularly evidenced in the lack of strict type casting. Legit development teams rely on this to effectively lock down their interfaces, implement error handling, etc etc etc.
I'm very dissappointed to see that languages (like C#), sponsored by the likes of M$ have been able to develop such mature OO languages so rapidly, while PHP remains... well... practically in the stone age.
Once these issues are addressed I think we'll see more support of PHP, and less resistance to its place in the enterprise. Abstraction is a stupid thing to bicker about. How long does it really take to write a good data abstraction layer - that can be repurposed. What's more important is the capability of the language.
Hopefully IBM will jump in here and kick things into high gear. Let's get rid of all the back support and compatabilities for legacy code in favor of maturing the language and increasing its value (and decreasing objections from the enterprise market)

daniel at cedilotte dot com (2005-11-03 09:58:10)

Another thing related to PHP vs ASP.
In PHP, it's possible to make sure your Include files are not included more than once. Where as in ASP/VBScript, you can't due to the fact that SSI is processed before the VB code.

ahumeniy at vtr dot net (2005-05-21 09:43:13)

I agree with Web Consultant concerning to ASP.net and .net framework. It's necessary an update to this article.
Currently, ASP.net is at the same level than PHP and, i would say that is better because i can choose what language to use (PHP is also available for .net by the way).
Thanks to it's common language runtime, .net technology allows the programer to choice wich language to use.
Also, ASP.net can make things that PHP don't such as manipulate the server's filesystem (y use that technique in the database system of my own CMS made with .net) and not only the files that are inside the website. Also, ASP.net make a lot easier for programmers to make programs that communicate with the web site without needing of a browser (I use that technique in a small application that allows my site's users to "navigate" the site and also send and receive personal messages a lot faster than with the web)
PHP needs to get improved to be better than ASP.net. I hope that the better wins

symcbean (2005-02-20 15:00:26)

I really must take issue with (Cash at nospam dot thesilverside dot com)'s comments regarding enterprise applications and PHP.
Yes, PHP is an interpreted language (but...PHP Accelerator? also you can write caching *with* PHP, also checkout http://shootout.alioth.debian.org/, and have you seen the benchmarks for Pharrot?). Adding more tiers into your application is a recipe for disaster since it reduces scalability by creating bottlenecks/crossovers and has a big impact on transparency. I'll admit that for a very few applications, then server hardware is more expensive than developer time - like if you're turning around more than 500000 hits/hour, then it may work out cheaper to develop in 'C' with half the servers than PHP, but this is far from the sort of volume I've seen on an enterprise application. There's a lot been written elsewhere on PHP and scalability which I won't repeat here.
There are issues with using PHP for this kind of application. Firstly managment of privilege - but that applies (AFAIK) to any web-based system. There's also the problem of namespace collisions in large apps.
Since I regularly develop embedded applications with PHP using HTTP as the communications substrate for transactions spanning 6 or more origanisations, I'd like to know whay I shouldn't be using PHP / processing synchronously, and how I can create a near real-time system without synchronous operation.
It'd be a sad world to live in where there was only one programming language/methodoly/idiom - diversity is a great thing. Java provides beans and struts, Coldfusion provides fast development and .NET....(suggestions please). PHP comes closest to solving my problems, many of which are very much in the enterprise applications domain.

Web Consultant Since 1994 (2005-01-19 11:26:57)

...Well, all I can say about ASP.NET and the .Net frameworks is that rather than adopt them we decided to switch all of our development to PHP and other open-source tools. We simply got tired of all the churing of the development platform from $soft: things like changing API's during final betas, undocumented api's etc.
Ive programmed in C, C++, VB, ASP (since the original beta in 1995) and ASP.Net, Com, Com+, .Net Frameworks and in C("sharp"). The fact of the matter is that most of these new and "improved" development tools dont save much, if any money, and are mostly, unnecessary. We have found PHP to be an excellent replacement for similar $soft tools and technologies for web development.
Its true that there is a bit more code required to supplement things that $soft and others give you for a price, but the bottom line is that most of these things are not very difficult to do properly. In our business there is a huge risk from not having access to source code and we simply cant be held hostage by a third party company: when you add up the dollar value of this risk for our business it far exceeds the few dollars we need to spend in extra supplemental coding - which is done once so its a one-time cost.

berjoza at bigmir dot net (2004-03-26 08:25:08)

How about PHP and JAVA?
You can use PHP vs JAVA in following order
1. In php.ini file add
- extension=php_java.dll
-
[Java]
java.class.path = "c:\usr\local\php\extensions\php_java.jar"
java.home = "c:\usr\local\j2sdk1.4.2_03"
java.library = "c:\usr\local\j2sdk1.4.2_03\jre\bin\server\jvm.dll"
java.library.path = "c:\usr\local\php\extensions"

Cash at nospam dot thesilverside dot com (2004-01-11 23:12:11)

To correctly utilize PHP in enterprise applications, one may want to bear in mind that if PHP is being used synchronously, it should be kept to the presentation layer only. Other languages that were previously mentioned througout the notes above (such as Perl, Java, and the .NET CLR... if you're on Windows) would be more appropriately used within the business process and data access layers. If you really want to maintain higher speed on presentation, then perhaps one would want to incorporate asynchronous instead of synchronous processing into the presentation layer of your application.
In other words, if you are using a connected data source, such as a SQL database, try shifting the processing time back a layer by providing a medium interval return from the data source to an XML file that the web service can access. This will allow your web presentation layer to load the data significantly faster than it is now. It will also give more resources back to PHP and your web service processes.
If you still cannot get the PHP processes back up to par, then you should consider using PHP as an asynchronous page constructor, thus shifting PHP itself back to the business process layer and allowing the web service (Apache, IIS, Netscape, etc.) to return HTML files instead.
Aside from page caching, (to my knowledge) you simply cannot get any faster than that.

Tricrokra (2003-10-26 05:28:55)

I have to note that a very big advantage of PHP over ASP is that PHP has much easier commands...

Take openening of a file in ASP...
First create a file object... I put this into a function because the line is simpy to long and I called it "Init fileobject"

<%
Initfileobject     'The Sub I created in order not to type that idot line all the time
Set Fil = FileObject.OpenTextFile(Server.MapPath("data")&"\datafile")
datavar = Fil.ReadLine
CloseFile Fil
Set Fil = Nothing
Set FileObject = Nothing
%>

Why always those objects...

The same thing in PHP

<?php
$fil 
fopen("data/datafile","r");
$datavar fgets($fil);
fclose($fil);
?>

That's all...

And that while VBScript is based on BASIC (BEGINNERS Allpurpose Symbolic Instruction Code)... 

I code too shortly in PHP to make a full analysis yet, but the complex object structues of VBScript is something I really put in question, PHP has a much easier syntax when it comes to that...

One of the first things I saw was that PHP is based on C, which is one of the hardest programming languages in the world. That makes the syntax of for example the "for" statement less to my desire, which I like better in VBScript (ASP)... If you are an experienced C or C++ programmer, I think PHP makes automaticly the best choice out of PHP vs ASP. 

But I did find out in only 1 hour that the syntax of PHP gives you much less typing than ASP, that is a fact. I think that for the rest the pick of language is pretty personal.

When it comes to stability. ASP servers crash very much. I don't think ASP itself is the evil one in this. ASP only runs on Windows servers, and we all know how much Windows crashes. I truely believe that also picks a part of the puzzle...

atoi_monte at hotmail dot com (2003-07-24 11:34:23)

---------------------------------
QUOTE:
This is a comparison between PHP and Java/JSP:
http://www.tek271.com/articles/JavaOrPhp.html
Any comments?
---------------------------------
Probably the worst comparison I have seen in a long while. They penalize PHP for class scope and global variables and such.
1) While that may be relevant for APPLICATION programming, it's totally irrelevant for web programming. Web programming, imho, is about being able to get a quick, organized solution out QUICKLY so that it can be maintained and dynamic. The global variables, lack of package system, and loosely typed nature of PHP makes it easier to use and get stuff done in, while the syntax is still clean and easy to maintain. On applications programming.. yes.. Java is a better solution. But for web programming, JSP doesn't hold a candle to PHP, imo.
2) With PHP 5, I would just like to remind everyone, there will be a lot of concessions to Java programmers (mostly to lure C++ hackers to PHP over C# or Java) like constants, abstract stuff, and access control. While it won't impact the programming that much ( you can still code just like you always have) you can at least feel more like C++ when we finally get to use PHP5.
dan

anonymous at coward dot com (2003-04-09 00:23:40)

As far as I can see, Web Consultant apparently missed the topic, which was "3. PHP vs. Cold Fusion", not "PHP vs. compiled languages (JSP,ASP.NET, and ColdFusion MX)".
We probably all agree that PHP, compared to what ColdFusion was at the time of the writing of that part of this FAQ, is far more capable of complex scripts, and also generally outperforms ColdFusion in similar tasks, too.
I'm not familiar with ColdFusion MX, but as it sounds like it's a rather new product, I would draw the conclusion that it isn't what the writer of this FAQ had in mind when addressing PHP vs. ColdFusion comparisons.
Surely, Web Consultant must have made the same conclusion based on his discovery that the FAQ is outdated and thus should be updated.
cheers.

Web Consultant (2003-04-04 13:39:06)

Sounds like this FAQ needs to be updated.
How about ASP.NET and .NET Framework?
How about ColdFusion MX?
PHP has limited/None out-of-the-box database integration with popular RDBMS(Oracle,SQL Server), integration with COM and to Java Servlet and Enterprise Javabeans, that alone make ColdFusion MX and ASP.NET an attractive development platform.
PHP might be good for developing non complex websites for no cost; however when you are developing enterprise web systems that have to integrate with many different flavor of sources .. php does not have the out-of-the-box functionality for the above needs.
"PHP is commonly said to be faster and more efficient for complex programming tasks and trying out new ideas. PHP is generally referred to as more stable and less resource intensive as well. "
I like to see proof of this statement. How is a interpreted languge faster and less resource intensive than a compiled languge(JSP,ASP.NET, and ColdFusion MX)?
ColdFusion MX Server cost about $1300, but the total built in functionality and versatility makes it a worthwhile. If you start out with PHP, ask yourself how much time and money you have in developing the source to provide the functionality you are looking for.
PHP vs ColdFusion MX
http://www.macromedia.com/devnet/mx/coldfusion/articles/php_cfmx.html

phalcomb at arbolnet dot com (2003-02-05 18:29:16)

My experience with ASP and PHP is about equal, I think they both serve equally as good of a purpose depending on what the programmer is trying to do. I do like the syntax of PHP a lot and the speed of it is great, although the client/server interactivity of ASP with Windows and MAC clients is what I'm excited to see grow with future versions of PHP.

mavi_br at someplace dot com (2002-12-13 17:02:35)

I've been working with PHP, JSP, Java and CFM for 2 years now.
I can tell that for web development only, php is not nearly as good as cfm on speed, on ease to use and on interaction.
On the other hand you just can't do anything very special with CF like opening a socket with the ease of php.
I would say : use what you need for your application, cfm is truly the fastest, as it has a daemon running instead of a per request, plus the ability to cache queries that is awesome.
php is fast but is a pain on some aspects and has loads of bugs.
JSP have almost no bug at all, or at least i did not find any, but it is hard to debug.
Good thing on JSP is that you can write real applications and have perfect interaction by using classes, plus it is much more of a serious language.The only problem is that you take at least twice times to make same program on JSP and it is not even close as well documented and easy to use as php.

dir at badblue dot com (2002-09-25 21:51:23)

To ahabra,
Very interesting page. I would ask the following, however as you investigate this topic further... you'll soon become the PHP vs. Java guru.

Your comparisons are interesting and well thought out. I would also add some higher-level (less computer-science oriented, simply because the task at hand is generating web pages 'on the fly'). As a pure CS language, there is no doubt that Java is superior. But as a web page generator, I have moved from a Java-centric approach to a PHP approach, leveraging servlets or beans as needed "under the covers".

Therefore, some higher-level things to consider:

1) Compare the complexity of real-world production applications (postnuke.com vs ? in content management, phpbb.com vs. ? in discussion boards, jpgraph vs. ? in graphing). In my mind, the proof is in the pudding - which technology results in the better, more production-ready applications? They may be out there for Java - I would just like to know where they are and who is using them.

2) Compare slinging (generation) of markup which is where PHP excels (as it was designed to sling markup - this includes features such as character transformations, variable accessibility, web page captures (see the fopen call which captures a web page in a single function call). Your point about a string being encapsulated in a string class is somewhat irrelevant if you are a programmer cranking markup. Embedding object-oriented code into a page can be much more painful (and slower to execute) than leveraging traditional coding techniques.

3) Compare native database and directory support. Java would have the advantage in generic database access (JDBC) but PHP has the advantage in LDAP support (JNDI has several bugs which we have run into - quite painful) and native database access (e.g., Oracle or MySQL integration).

Overall, well done - and a very popular topic! It's worth building it out further.

developer at i-space dot org (2002-03-04 08:34:16)

If you ever tried to configure a web server for WAP, serving WML content you know it's not an easy job. You can easily make dynamic WML pages for mobile phone users with PHP. All the options and extras from DB+PHP oriented web-site can easily be transfomed into a WAP version of your site. With a single line - Header("Content-type: text/vnd.wap.wml"); you can be in another "mobile" dimension :). Take all you need ... and even more.

易百教程