PHP VS. ASP.NET

Written by Sameer on May 8, 2008 in: .NET articles, Work Related |
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

22 Comments »

  • You might want to take a look at the LAMM stack (linux apache mysql mono). ASP.NET apps run just dandy in *nix with mono.

    Cheers,

    Greg

    Comment by Greg Young — May 22, 2008
  • You gotta admit that ASP.NET has one failing. ViewState and WebForms. Fortunately it’s not difficult to replace that monstrocity with your own httphandlers/modules or something like MonoRail, Promesh.NET, ASP.NET MVC (When it comes out), etc.

    Comment by Lucas Goodwin — May 24, 2008
  • I have to agree with Lucas, however, advantages of .NET are amazing, development time is so much faster in rich Visual Studio Interface.

    Another interesting article:

    http://www.prosperwebsolutions.co.uk/blog/2008/04/19/ASPNETVSPHP.aspx

    Comment by Josh Smigin — June 7, 2008
  • The only thing lacking in the PHP realm is a solid IDE.

    PHP does everything .NET does. There is even a very matured framework out there named Prado that is modelled after MSFT’s MVC approach. You can check it out @ http://www.pradosoft.com

    Comment by lami — June 27, 2008
  • Besides the greater argument…Ever heard of Zend IDE?

    Also, better bang for the buck??? How much do you expect a LAMP install to cost? A whole lot of nothing. Sounds like a whole lot of bang for NO buck.

    Will rant more later..

    -W

    Comment by Will Mason — July 29, 2008
  • I am amazed people praise the visual studio development environment. it think it is as clunky as hell.

    also the asp.net event/viewstate driven model was a huge leap in the dark: do we really need events to gather information from a webpage?

    i have found development timescales (i commision as a manger now) have not shrunk as a result of dotnet, and that maintenance of code has become a greater problem than under scripting approaches.

    Comment by dave — August 10, 2008
  • Hi Will. Total Cost of Ownership is a much more comprehensive way to look at it. Just the installation and hosting cost is not enough of a comparison. You also have to factor in development time, how easy it is to do bug fixes, unit testing, and so on… You made a good point which I did not cover in my article, so more on this topic coming soon… :)

    Comment by Sameer — September 20, 2008
  • PHP, in my humble opinion, scores well over ASP.net.

    Here are the reasons:

    Power to the people: Need simple encryption like MD5/SHA for storing passwords? Buy the library (and spend even more)from microsoft. With PHP, you get it all free.

    Need a site in 20 minutes? Try Joomla.
    Need a full fledged Shopping cart to run your superstore online? Try OSCommerce.
    Need a blog in what? 3 minutes? Give me $50 and I’ll do it with wordpress.

    Hey, Lehman Brothers fell big time. What if Microsoft… sorry, I know I went a bit too far :). Don’t see open source falling anytime even in a bad, bad economy.

    With Vista now, you must switch to it or your support (patches for virus) will be ending soon for XP. If you don’t switch before the support ends, you gonna fall bigtime. Has anyone heard of support being stopped for Open source?

    Same application developed in JSP, ASP and PHP . Result - PHP is fastest.

    Highest number of sites in the world are on PHP. Even Yahoo.

    Gotta run now, or will be late for office

    Comment by Nikhil Narayan — September 27, 2008
  • Sounds like you were comparing little PHP knowledge and experience against ASP.NET. PHP 5 with the right framework (codeigniter for example) will take care of all like caching and reusing code components with one line of code. You argue a PHP project costs more because of a longer development time? Well this just not true. This has nothing to do with the language but the developer. A seasoned PHP developer will known which framework, library, and tools to use making development just as fast if not faster than an ASP.NET project.

    I will agree with the fact with PHP you have known where to get a good framework or library to do a lot of the leg work like caching and component re-use where in ASP.NET it comes with it out of the box (or at least the option to buy comes out of the box).

    Comment by Charles — October 3, 2008
  • Dave, how would you even be sure that your scripts are all valid? Since they are interpreted, you can’t compare them..

    Charles, you are right. I am comparing ASP.NET to my very little PHP knowledge. But apples to apples, a seasoned PHP developer vs a seasoned ASP.NET developer, would you agree .NET development is more maintainable?

    For example, with PHP, how would you even ensure that your code is valid? Since its not compiled, how can you verify.. ?

    Comment by salibhai — October 3, 2008
  • I like PHP5 and I like C#. I am currently reviewing ProMesh.net (C# thing mentioned above) for porting our CMS solution from PHP5 to .NET.

    There are cases where a Client insists on Microsoft. In those cases we want a good solution, so C# is our preferred language in those cases.

    PHP5 vs .NET, I am a big fan of “strongly typed” languages (C/Java/C#,etc). PHP was at first an issue for myself, I was used to declaring my variables, etc and PHP was lose on variables. Today, I find PHP5+ just crazy cool. It is very flexible and with proper sanitation of user-input it’s safe. I have pages/queries cached and PHP Zend optimized — fast. The .NET side, C# is very nice and with ProMesh, it’s much easier to implement websites. C# is just a great language. (Usage: 90% PHP right now)

    Tools…
    Using the proper tools, PHP5 does have tab-completion of functions, even custom ones (using PHP doc). Look at Eclipse for PHP and Komodo Edit (and others).

    RIA
    Ajax or RIA can be done with either C#/PHP (jQuery,Flash,Silverlight).

    I am leaning towards PHP for being so flexible.

    Comment by Paul — October 8, 2008
  • [...] goes So for me, the clear winner is Wordpress (even though its not running .NET). I claimed that .NET is superior to PHP, however, of course, that does not mean that every single software written in PHP sucks, nor that [...]

    Pingback by .NET Blogging Softwares — October 13, 2008
  • I just would like to make a correction of two mistakes the writer has made in the article. First, the first official version of PHP, PHP3, was released in June 1998 by the very small development team at that time. In fact, PHP4 in May 2000 is the first widely known version of PHP. Second, ASP has been widely known and used since December 1996 when ASP1 was distributed with IIS3 by Microsoft, and every one knows what Microsoft was at that time.

    Comment by Nasser — October 20, 2008
  • .NET vs. PHP is not an apples to apples comparison. PHP + some application framework (some were mentioned above and I like CakePHP) vs. .Net is more like it. You see PHP is a LANGUAGE, where as .NET is an application FRAMEWORK. So PHP should be compared to C#. CakePHP should be compared to ASP.NET.

    The thing I was most surprised to read was when the author said, “I couldn’t find a decent IDE (i.e. editor)”. What? I don’t know what the names of the popular Mac IDEs are, but I know I’ve seen some with intellisense via screen casts. For any platform, including Windows, there is Eclipse with the PHP plugin (all free). SVN, TortoiseSVN, and/or Subclipse take the place of SourceSafe and can handle more than source code. Aptana is a version of Eclipse that is perhaps a better web dev IDE out-of-the-box. There are also PHP plugins for MS Visual Studio if that’s what you’re already using! And there are even SVN plugins for MSVS too!

    Personally, I think the whole “versus” arguments don’t resolve to a clear better choice. Any web problem can be solved with either solution, or nearly so. It comes down to programmers’ skills with their language(s) of choice. Can the programmer accomplish the task in XYZ language/framework? That’s what matters in the real world.

    Comment by Ryan — October 20, 2008
  • I did try Eclipse + PHP Plugin but it was a complicated mess and I couldn’t get it to work :(

    Your comments are good. thanks Ryan

    Comment by Sameer Alibhai — October 20, 2008
  • For those with the same experience as Sameer, try Aptana. Yes, it’s a big download, but the install is more ‘Windows app-like’. Quite a different experience. I’ve used both. I will also be trying out one of the VS PHP plugins soon at my day job, so I’ll have to see how that compares.

    Comment by Ryan — October 20, 2008
  • I think the whole debate is just wasting your time. None of the people on both side, knows the opposite side.
    Look at Nikhil Narayan :
    Power to the people: Need simple encryption like MD5/SHA for storing passwords? Buy the library (and spend even more)from microsoft. With PHP, you get it all free.
    !!! Ooops, did you even use .NET framework? It got built-in support for it!!!!

    Need a site in 20 minutes? Try Joomla.
    .NET: Or try Dot Net Nuke!
    Need a full fledged Shopping cart to run your superstore online? Try OSCommerce.
    .NET: Or try Dash-ShoppingCart, or Dot-ShoppingCart….
    Need a blog in what? 3 minutes? Give me $50 and I’ll do it with wordpress.
    .NET Or try BlogEngine.net
    This is correct about .NET fanatics as well.

    Comment by Jack Ronin — October 25, 2008
  • There is one really good thing about ASP.NET and that’s AJAX. That partial page push refresh is killer. It’s fairly easy to develop web based equivalents to my grid oriented desktop application. Now we are looking at WPF so that the desktop applications are just ports of the web stuff. Two implementations with the same code base.

    On the other hand I have a bunch of heavy hitter clients using web apps that we wrote in PHP / Apache running on Windows servers. Light weight as far as resource consumption. IDE? What IDE? EditPlus and knowing what you are doing. Emphasis on the latter.

    There are some cool tools for PHP now and lot’s of people use it every day. I keep hearing that VB is dead. With Dot Net that’s not so. VB and C# can produce identical runtimes.

    Comment by Charles Kincaid — October 31, 2008
  • For IDE, I’ve discovered NetBeans 6.5RC has great PHP support. Code completion, intellisense, debugging using xdebug which took me awhile to configure on Mac Leopard; but go to Komodo site and download the xdebug binary. NetBeans is free. I’ve tried Aptana, Ecplise + PHP, and Textmate. Now my favorite is NetBeans. For PHP framework, I am amazed by ZendFramework and CodeIgniter, if you are a Ruby on Rails fan. I code in C#/ASP.NET for a living but I am considering PHP for some side projects. Also checkout Phalanger project at codeplex. It compiles your PHP code to .NET bytecodes.

    I don’t have strong opinion which is better — PHP or ASP.NET. I’ll use both if it pays the bill. Learn from both camps. Learn a new language every year. Checkout Django and Pinax(it’s nice), and Ruby/Ruby on Rails. Buy a Mac laptop. Great for development. Try mono. See Dekiwiki. It’s a PHP frontend with RESTful .NET running in mono in the backend.

    Comment by Rolly — November 19, 2008
  • Also checkout these two wonderful opensource projects: Magento is an awesome eCommerce application in PHP/ZendFramework. ELGG is a cool opensocial application also in PHP. The web is alive with excitement! Cheers!

    Comment by Rolly — November 19, 2008
  • hi
    about the php ide, i suggest you to use Aptana, a great free web develop IDE with PHP support.
    Thanks.

    Comment by cao — November 24, 2008
  • At work, we use C#, but we now have a need for PHP, so I’ve just bought VS.PHP, a plugin for Visual Studio that supports PHP and includes both the XDEBUG and DBG modules for debugging. It is supposed to have intellisense and many bells and whistles. As mentioned previously, I’ve used Aptana and Eclipse + PHPIDE, so it will be interesting to compare my experience with the new tool.

    Comment by Ryan — November 24, 2008

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Theme Design by TheBuckmaker