This is a very shallow comparison of my experiences with PHP and ASP.NET
Don’t take this as a religious war or something, the idea is just some basic comparison.
 
Here is a summary: If you are choosing which technology to use to build an application, use .NET. You will get more bang for the buck. With the same effort you will be able to build a much more rich user interface. 
 
My Disclaimer: Keep in mind there are a lot of great libraries and tools for PHP which I never got to use, I just had a simple PSPad text editor and my handy PHP web site.  I really wanted some “Intellisense” style code completion but I could not get it to work with PHP since I couldn’t find a decent IDE (i.e. editor)
 
However, it all depends on your requirements. For example, if you are selling something that most of your customers will be on a shared linux hosting environment, then why would you use .NET ? A good example is the software Clipshare, which is a clone of Youtube. The sites purchasing this product are mainly shared hosting customers who have PHP but not .NET. And Mono (.NET port on Linux) is not yet stable or popular enough to use.
 
I did some PHP programming before I started doing .NET fulltime. Before then I couldn’t say much about it, but after working with .NET for a few years now, I have much to say.
.NET does a very good job in handling the whole life cycle. With PHP you have to do it manually.   For example, there is no such concept of “Postback” with PHP. This is such a basic thing that you can easily check with .NET to see if the page has been submitted and what button was pressed. For example if your “btnSubmit” was pressed, it will call btnSubmit_Click. With PHP, you have to do this manually. Not to mention how mish mashed your PHP page can be in terms of mixed code and style/HTML elements.

How about caching? I wanted to implement caching with PHP and I had a fun time, I had to check if the cached output file existed, and then if so, then check how old it is, and so on… Yeah okay again maybe there are some nice components already done for this, but I didn’t have to look very hard to do it with .NET, I simply added a CacheDependency on an XML file (or whatever the case was), and BOOM! It regenerated the file whenever necessary.
 
How about reusable components? With .NET you can create ASCX (Custom Controls) that you can place within a page that expose certain properties and the control itself maintains its state, can have buttons, etc, etc.

How about master pages (i.e. templates) in .NET? Again, super cool reusability! You can create pages with repeatable parts, with headers, footers, all sorts of fun stuff.

I can go on and on…  but in general, the more I use .NET, the more impressed I am with it. However, what makes it not-so-practical is how expensive Windows Server hosting is.  In summary .NET kicks butt!
 
Update Oct 8 2008

 
I wanted to add some more meat to this article based on the comments below

I mentioned that getting Windows Server hosting is more expensive.. However, lets look at this in perspective.  What’s more expensive – server cost, or development cost?  Development cost in most cases far outweighs any particular savings of a Windows license.  What this means is even if your application takes two or three times as long to write, then you have lost any potential savings from running a "free" linux box. 

Also, I would like to hear about how to unit test with PHP. 

.NET offers unit testing via many different frameworks, NUnit probably being the most popular right now.   I would like to know how can I unit test in PHP?  There is also an extension for NUnit available called NUnitAsp that allows me to test my interface.  Another notable extension for Nunit is an automatic database rollback.  SWEET!  More details to come as time goes by.

Other Interesting Posts

 

91 Responses to PHP VS. ASP.NET

  1. viral chhatrola says:

    can you tell the difference between mvc frame work of PHP and .NET

  2. peter says:

    as you said this is a shallow comparison – a fair comparison would be say, framework comparison rather than the framework to language comparison you did – zend framework has hooks to lifecycle events (predispatch postdispatch etc); zend also has several caching options; zend layout pages transaltes to what a master page is in .net; you can use phpunit for unit testing; partial views are reusable components in zend…I could go on and on …do your homework before blogging

  3. Stefan says:

    Except that in PHP, everything you wanna do has most-likely already been done, and you can just copy paste, which far outweights the development costs that certainly are not lower in ASP.NET. PostBacks are anyway a bad idea (use AJAX and MVC, so I wouldn’t say PHP is bad, because it’s meant for AJAX, and not PostBacks, and actively discourages the use of PostBacks) and that you can run PHP on Windows as well. The speed of ASP.NET with postbacks and viewstate certainly is slower than PHP (although the compiled C# language by itselfs is by far faster than interpreted PHP). Besides, you can also run ASP.NET on a Linux box (you can develop on Windows using VisualStudio). That way, you get the best of both worlds !

  4. DrOhReally says:

    to be fair I find it much easier to work with asp.net, everything is at your fingertips (intellisense is a big bonus), unlike PHP where you need to do everything manually unless you get a third party framework which most of the time is not free to use commertially. I do prefer the php for MySQL, I’ve never liked the MSSQL hehe

Leave a Reply

Your email address will not be published. Required fields are marked *

*


5 + = 7

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>