PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<PHP and COMMigrating from PHP 2 to PHP 3>
view the version of this page
Last updated: Thu, 21 Aug 2003

Chapter 34. PHP and other languages

PHP is the best language for web programing, but what about other languages?

1. PHP vs. ASP?
2. Is there an ASP to PHP converter?
3. PHP vs. Cold Fusion?
4. PHP vs. Perl?

1. PHP vs. ASP?

ASP is not really a language in itself, it's an acronym for Active Server Pages, the actual language used to program ASP with is Visual Basic Script or JScript. The biggest drawback of ASP is that it's a proprietary system that is natively used only on Microsoft Internet Information Server (IIS). This limits it's availability to Win32 based servers. There are a couple of projects in the works that allows ASP to run in other environments and webservers: InstantASP from Halcyon (commercial), Chili!Soft ASP from Chili!Soft (commercial). ASP is said to be a slower and more cumbersome language than PHP, less stable as well. Some of the pros of ASP is that since it primarily uses VBScript it's relatively easy to pick up the language if you're already know how to program in Visual Basic. ASP support is also enabled by default in the IIS server making it easy to get up and running. The components built in ASP are really limited, so if you need to use "advanced" features like interacting with FTP servers, you need to buy additional components.

2. Is there an ASP to PHP converter?

Yes, the server-side asp2php is the one most often referred to as well as this client-side option.

3. PHP vs. Cold Fusion?

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. Cold Fusion has better error handling, database abstraction and date parsing although database abstraction is addressed in PHP 4. Another thing that is listed as one of Cold Fusion's strengths is its excellent search engine, but it has been mentioned that a search engine is not something that should be included in a web scripting language. PHP runs on almost every platform there is; Cold Fusion is only available on Win32, Solaris, Linux and HP/UX. Cold Fusion has a good IDE and is generally easier to get started with, whereas PHP initially requires more programming knowledge. Cold Fusion is designed with non-programmers in mind, while PHP is focused on programmers.

A great summary by Michael J Sheldon on this topic has been posted to the PHP mailing list. A copy can be found here.

4. PHP vs. Perl?

The biggest advantage of PHP over Perl is that PHP was designed for scripting for the web where Perl was designed to do a lot more and can because of this get very complicated. The flexibility / complexity of Perl makes it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format without losing flexibility. PHP is easier to integrate into existing HTML than Perl. PHP has pretty much all the 'good' functionality of Perl: constructs, syntax and so on, without making it as complicated as Perl can be. Perl is a very tried and true language, it's been around since the late eighties, but PHP is maturing very quickly.



add a note add a note User Contributed Notes
PHP and other languages
Tricrokra
26-Oct-2003 09:28
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...
rentaprogrammer at yahoo dot com
24-Oct-2003 07:21
As a C programmer of 20 years (C++ for the last ten), I have to chuckle when I see such similarity in languages like PHP and Perl to good old fashioned C. It looks like most of the functions in PHP match 1 for 1 to the standard C libraries. I've only been dabbling in PHP for a couple of weeks. Although I was very reluctant to embrace open source software when I had first heard of it, I've been emersed in it for a few months and am now a big proponent.

I have used ASP/VBScript for the past five years but look forward to developing skills in PHP. PHP taps my C/C++ skills whereas ASP does not. Thankfully, my employer has been gracious enough to indulge my craving to learn PHP and MySQL (he needs both for an upcoming project).
Phlogistic
02-Aug-2003 05:39
Hey Web Consultant, JSP technology IS interpreted. 

JSP pages are translated to java implicit servlets, then bytecode, then run on a JVM...a Java Virtual Machine.  It is impossible to execute anything Java without the Java Virtual Machine, therefore it is interpreted.

java.sun.com/docs/books/tutorial/getStarted/intro/definition.html
David
02-Aug-2003 12:40
I've been developing web sites & apps for about 7 years and have developed in everything from perl & lasso (early days) to ASP/VB, JSP, and PHP.

When it comes to web apps, PHP wins hands down.  PHP is the only language born out of the need to develop in the web environment itself. Rapid development time and platform portability = winner.  PHP provides so much flexibility.

-----------------------------------------------------
Some generalizations:

JSP = Way to much JAVA dependency & overkill
ASP = Clumsy code and lots of lines to do simple things
PHP = Made for the web
------------------------------------------------------

If you are concerned about "enterprise" scalability & performance don't get caught up in which language to use - rather, invest in the right hardware and use PHP!!!  Nothing kills a good app better than an awful underlying architecture.

- David
atoi_monte at hotmail dot com
25-Jul-2003 01:34
---------------------------------
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
Gecko
22-May-2003 04:19
I also have years of expierience in PHP, ColdFusion, ASP and Java. Each of them has his advantages and disadvantages depending on the project (size, complexity, maintainability, developers involved and so on).
To me, the cleanest way, also concerning future maintenance, is to use a system supporting the MVC pattern. It needs a bit more time at the beginning, but it pays off in the long term.
My favourite technology so far is using one of the open source Java frameworks (e.g. JPublish or Apache Turbine) with a template engine as the viewer component (e.g. Apache Velocity). I don't like JSP, it was an attempt from SUN to compete with ASP. The developer implements the business logic with Java and the Web designer implements the HTML stuff in the template.
anonymous at coward dot com
09-Apr-2003 02:23
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
05-Apr-2003 04:39
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
richard_wendel at hotmail dot com
16-Mar-2003 02:33
About PHP v. JSP/EJBs/Servlets:

The primary feature I enjoy about the Java Server diagram is persistant objects, because the JVM stays loaded and running, I can build up a static object in one of my classes that is accessible to any of my other running apps.
phalcomb at arbolnet dot com
06-Feb-2003 10:29
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.
sanity check
01-Jan-2003 09:03
If you read the rest of the manual you'll discover that PHP4 is runtime-compiled into bytecode, like Perl. And generally it's installed as a server extension, like mod_perl. So Perl has no advantage in this area. PHP's performance generally is better, even without taking advantage of accelerators such as the Zend Accelerator or APC, which cache the generated bytecode.
mavi_br at someplace dot com
14-Dec-2002 09:02
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.
nospam at phppatterns dot com
23-Nov-2002 08:54
Here's a PHP coders response to Abduls "Java or PHP" article?

"PHP or Java?": http://www.phppatterns.com/index.php/article/articleview/12/1/3/
dir at badblue dot com
26-Sep-2002 11:51
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.
ahabra at yahoo.com
09-Aug-2002 02:46
This is a comparison between PHP and Java/JSP:

http://www.tek271.com/articles/JavaOrPhp.html

Any comments?
php at sungate dot nl
28-Jun-2002 07:11
Oh, BTW the other comment just posted should include mentioning that the article about PHP and .NET is also about C Sharp (C#) or VB. As long as the modules/libraries created for .NET are build with the instructions on that page they should be accessable within COM after the wrapping. That's what the article is telling me, haven't tried it myself yet, but will start with C# soon to have a look at it. If it is easy/simple, this would mean a lot of power behind PHP coming our way. And if I'am not wrong even on Linux (GTK#) the whole bunch of new tech will give us kick-ass power.
php at sungate dot nl
28-Jun-2002 07:00
Well, about PHP and .NET.... I saw an article about using the COM structure for wrapping around .NET's architecture.

http://www.informit.com/content/
index.asp?product_id=
%7BD52A041D-4FCB-44C9-BE8C-
E2D446D3A999%7D&null

(sorry for cutting, otherwise it wouldn't let me submitting the text.... = ( )

Looks very odd and complicated, but as always... People who are using or even developing for PHP come up with solutions for any kind of much used technology. So just wait and see (PHP with Zend 2.+) and .NET will be supported by PHP very soon, just because Open Source is as flexible as where the main stream wants to go.
bb_NNooSSppaamm at intracom dot net
12-Mar-2002 09:32
Cold Fusion vs. PHP:
What about the price?  I started a few years back designing web applications in CF with its powerful database interfacing.  Convincing management to spend the money on the CF server & my app can be VERY difficult.  I have since switched ALL my apps to PHP.  I haven't come accross a situation it couldn't handle (granted, with a decent amount of time spent in some cases).  The savings and 'sellability' well make up for slight difficulties I've had to deal with.

BB, FFASpector
developer at i-space dot org
05-Mar-2002 12:34
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.
pyranf at hotmail dot com
01-Feb-2002 01:34
One other thing that should be mentioned about ASP vs. PHP is session support.  I find ASPs session management to be much simpler and more intuitive.  For example, if I want to get and set a variable, I do this:

Session("myVar") = "bob"
strBlah = Session("myVar")

In addition, Session variables stay around through the entire session (until the user closes the browser), so there is no need for session_start() at the beginning of each page.

That being said, I rather like PHP more syntactically and functionally.  The C-like syntax is much easier for me to read and write, and the native functions it supports is... extensive to say the least.

Still, ASP has better session management.
diegof79NOSPAM at yahoo dot NOSPAM dot com dot ar
01-Feb-2002 01:24
What about PHP vs. JSP?
One of the problems I see in PHP is lack to support some design pattern practices like MVC.
Yes it support the use of Java classes... but how good is this support?
Can use PHP as an EJB client (COM sucks because is Win32 only)
There is any equivalent to taglibraries or the Struts framework (http://jakarta.apache.org/struts) in PHP?
In favor of PHP... is really fast!, and easy to learn, ideal for small/medium websites...but (I think) not so good for enterprise web based applications.
nick at divbyzero dot com
30-Aug-2001 05:45
Actually, ASP isn't as terrible as one might think, if you have a background in Javascript (or other object-based languages with dot-notation (object.object.function()). VBScript is a pain, true (cuz it looks, feels, and smells of VB), but JScript is a lot nicer and syntactically looks like Javascript with extra functions added for server-side stuff (ie., file i/o) that Javascript can't do client-side.

And while most of the code samples on the net and documentation talks about VBScript, JScript docs and manuals can be found on M$'s sites in a few places.

Where VBScript has that painful

IF ...
ENDIF

crap, JScript has the friendly

if () {
 // ...
}

and even

for (indexVar in ArrayName) {
  // ...
}

stuff, very much like PHP's foreach() looping.

Once you get around the bulky object syntax for opening, closing, writing, appending files/folders, it's not too bad. Good regExp handling, too. And translating from PHP to ASP and back again is a good programmatic exercise for those trying to stay grounded in object (Javascript/Jscript) and function (PHP) notation differences.

eg., preg_replace("/pattern/","replacement",$source);
becomes source.replace(/pattern,"replacement");
etc.

For examples of code workarounds I've built to translate PHP functionality to ASP and vice versa (like translating PHP's file() into ASP), check out: http://divbyzero.com/PHP/ and http://divbyzero.com/ASP/

- nick@divbyzero.com
corradol at mclink dot it
29-Jul-2001 06:44
ASP rely on a scripting engine which out-of-the-box support VBScript and JScript (MS version of JavaScript). Support for other languages (ie Perl) is available throught add-on modules.

<PHP and COMMigrating from PHP 2 to PHP 3>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST