ASP.NET and PHP
Virtually every medium or large web site now uses some kind of server-side scripting to generate web pages and interactive features instead of static html. A number of technologies are used for this purpose, including PHP, ASP.NET, Perl, ColdFusion, and JSP. This paper will look at Microsoft’s ASP.NET and an open-source alternative, PHP, and compare them in terms of cost, performance, support, features and ease of use for web development.
Comparing ASP and PHP can be difficult because they are not exactly the same class of software. PHP is simply a server-side scripting language. The PHP homepage describes it as â€œa widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.â€1 ASP, more properly ASP.NET, is not a language per se, and allows users to program Microsoft Internet Information Services (IIS) in Jscript, Vbscript, and C#, among others. ASP.NET is a little harder to define than PHP. ASP stands for Active Server Pages, and .NET, according to Microsoft, â€œis a set of Microsoft software technologies for connecting information, people, systems, and devices. It enables a high level of software integration through the use of Web servicesâ€”small, discrete, building-block applications that connect to each other as well as to other, larger applications over the Internet.â€2
Despite major structural differences, the two can and should be compared because they can be used to create the same kinds of medium-to-large, dynamic, often database-driven web sites. Server-side scripting allows sites to easily edit and update information, offer interactive features like forums and personalization, and track user traffic.
Background: Server-side scripting
Serve-side scripting gives web developers more control over how web pages are built and served and allows much more interactivity. When a user follows a link to a web site, they send a request to the site’s web server. The server responds by sending the user the html code, which the user’s web browser uses to display the page.
When a user follows a link to a site using server-side scripting, the first thing the web server does is check the page for scripts. Any scripts that are there are then run, for example querying a database for the last ten messages posted in the site’s forum. After the scripts are run, the server sends the resulting html to the user, which the browser uses to display the page.
There a number of features to consider when determining cost. Total Cost of Ownership (TCO) includes not only hardware and software but salaries and how efficiently time us used. For hardware and software, we have to consider four factors: the cost of the server hardware, the cost of the server operating system, the cost of the web server, and the cost of the language/environment itself.
PHP is the clear winner in the hardware/software cost categoryâ€”it can be run on Linux with the Apache web server, both available for free. Windows Server is required for IIS and ASP.NET, and Windows Server 2003, Web Edition is available for $399.3 In terms of physical hardware, Linux with Apache and PHP can in general handle more users one the same hardware or the same users on less hardware than Windows, IIS and ASP.NET (see Performance below).
Hardware and software costs are less important than labor. It is impossible to determine in general which language requires more development time. Productivity is highly dependent on the task at hand and the skill and experience of the developer. Although PHP may be a little easier for novices to learn (more on that below), there is no way to say PHP is more efficient than ASP.NET or vice-versa.
There is some evidence, however, that PHP programmers are less expensive than their ASP.NET counterparts. One site showed the median salary of PHP web developers as $43,500 4 and ASP web developer as $50,000 5. Similarly, in a survey by Dice.com, Web Developers/Programmers with the skill PHP averaged $56,406 per year where ASP averaged $66,721.6 This does not seem to be due to PHP attracting beginners, since the same survey reported nearly identical experience for both groups (PHP 3.58 years, ASP 3.56 years). A simple monster.com search for â€œPHPâ€ returned 594 jobs, where â€œASPâ€ returned 4288, so the discrepancy may be due to a weaker labor market for PHP developers. In any event, PHP developers are less expensive.
Performance can be difficult to gage, since each language has particular strengths and weaknesses and optimization differs from language to language and problem to problem. Most code, in fact, is not written exclusively for speed but instead strikes a balance between speed and code legibility and reuse. Also, speed is often limited by database connections or Internet connection speed.
Still, for web programming languages performance is a important measure in TCO. If a particular web page will take 15 percent less time to display using one language rather than another, that may mean 15 percent less hardware to purchase, 15 percent less network traffic and bandwidth, or 15 percent more customers using the site at the same time. Since designing and implementing a comprehensive benchmarking suite is beyond the scope of this paper, it’s useful to look at an existing case for illustration.
WrenSoft makes versions of their Zoom search engine in both PHP and ASP. Since this company has no doubt attempted to get the best performance on either platform, we can assume they are not favoring one or the other. In all tests, PHP performed searches faster than ASP. They found PHP to be twice as fast on average.7
Both ASP.NET and PHP have large online communities voluntarily supporting each other, although PHP, perhaps because of it’s open source nature, leads in this measure. In terms of official support, PHP has a very easy-to-use manual available online at http://www.php.net/manual/en/, and ASP.NET has information available at Microsoft’s http://msdn.microsoft.com and http://www.asp.net. PHP’s documentation is easier to use for two main reasonsâ€”first, it incorporates user feedback directly into the manual itself, which can be very helpful. Many problems developers might face have been faced before by others and solutions are often posted right in the manual. Second, ASP.NET is part of the .NET framework, which is a much bigger system to document than a single language like PHP. Below are screenshots of functions to convert a string number to an integer in PHP and ASP.NET.
Sample PHP manual pageâ€”note the user comments at the bottom.
Sample ASP.NET manual pageâ€”note the difficulty of describing syntax in several languages at once.
ASP.NET definitely has more features than PHP. ASP allows developers to program in as many as 25 different languages, with VB.NET, C#, and JScript.NET included by default.8 In addition, developers can more easily integrate Microsoft Office applications, and ASP.NET’s Vbscript, C# and Jscript, are object-oriented programming (OOP) languages with stricter typing than PHP.9
The sheer number of features may not be particularly important to a specific web site, however. Integration with Office may or may not matter, and there is particular argument over the usefulness of the last two features. PHP supports OOP, allowing users to create classes with members and methods, but it does not allow completely private members. This means that a programmer writing a bicycle customizer for a bicycle shop’s web site can organize his code into a bicycle class with all the information and functions for bicycles in one place, but cannot ensure some later programmer does not ignore the functions and modify the data directly. On the other hand, these ASP.NET languages enforce OOP, which can be overkill for very simple functions and pages. Strict typing means that each variable has a specific type, so that the integer 4 is not equal to the string â€œ4.â€ For many web applications, PHP’s loose typing can be easier to work with, because values do not need to be converted for comparison. Depending on the individual developer’s opinion, PHP’s lack in these areas may really be advantages.
PHP does gain some features simply by being open source. For one thing, it is available for a number of platforms, where ASP.NET is only available for Windows. That means programmers can write and test pages on their Windows PC’s then upload them to a live Apache server running on BSD or a Windows 2000 Server running IIS or a Mac OSX server running Apache. In addition, the source code is freely available, so if a developer needed they could rewrite how PHP itself works, although there aren’t many situations where this would be beneficial.
Ease of Use
With programming languages there are a few different ways to look at ease of use. First is learnability, which is often related to the developer’s skill level and previous languages learned. The second aspect is code reusability, or how easy it is for developers to reuse code or borrow pre-written code from others.
Neither of these can be measured objectively. A developer with Visual Basic experience, for example, will no doubt find ASP.NET/Vbscript a cinch compared to PHP. But PHP does seem to be generally easier to start using than ASP.NET, in many ways because PHP is just a scripting language designed for creating web pages while ASP.NET is part of a large, very complicated .NET framework.
PHP is definitely easier to learn for free on the web. A Google search for â€œPHP tutorialâ€ returned 2,180,000 pages, while the equivalent â€œASP.NET tutorialâ€ returned only 344,000. The web seems filled with well-written, simple tutorials to get a developer up to speed with PHP, and while there are equivalent sites for ASP the PHP tutorials seem much better for beginnersâ€”PHP programmers seem genuinely interested in sharing their knowledge. In the print world there are more ASP resourcesâ€”an Amazon.com for â€œASP.NETâ€ found 7502 books while the equivalent â€œPHPâ€ search found only 1154.
Reusability is harder to judge. There are a large number of functions, classes, and other PHP code available online, which developers can use instead of reinventing the wheel each time they begin a project. On the other hand, one of the reasons to use OOP is code reuse, and PHP does not enforce OOP.
It is hard to make a generic recommendation without a lot more details. In general, if the project is smaller, needs to be done on a limited budget, and could benefit from the large amount of freely available code on the web, PHP is probably the right choice. If, on the other hand, the project requires integration with Windows or Microsoft Office, the company has already made a large investment in Microsoft technologies, or there will be a large number of developers who wish to work in different languages, ASP.NET is the choice. PHP is more flexible in other ways, allowing developers to use virtually any operating system or web server. The fact that PHP is open source is not very important in and of itself for most projects, since most website will not need to add anything to the language itself. The fact that it is open source has, though, attracted a lot of like-minded developers, creating a wealth of open source PHP projects. Taking into consideration the factors weighed above, PHP would be my choice for most web projects.
1. PHP: Hypertext Processor. 2004. <http://www.php.net/>. (15 February 2004).
2. â€œDefining the Basic Elements of .NET.â€ Microsoft. 24 January 2003.
<http://www.microsoft.com/net/basics/whatis.asp>. (15 February 2004).
3. â€œWindows Server 2003 Pricing.â€ Microsoft. 2004.
<http://www.microsoft.com/windowsserver2003/howtobuy/licensing/pricing.mspx> (15 February 2004).
<http://www.payscale.com/salary-survey/vid-4015/fid-6886> (15 February 2004).
5. â€œPayScale – Microsoft Active Server Pages (ASP) Salary Survey, Salaries, Wages, Compensation.â€ Payscale. 2004. <http://www.payscale.com/salary-survey/vid-3677/fid-6886> (15 February 2004).
<http://marketing.dice.com/rateresults/fte.asp> (15 February 2004).
7. â€œWrenSoft – Zoom Search Engine – Benchmarking PHP vs ASP.â€ Wrensoft. 2003. <http://www.wrensoft.com/zoom/benchmarks.html> (15 February 2004).
<http://www.asp.net/whitepaper/whyaspnet.aspx?tabindex=0&tabid=1> (15 February 2004).
9. Lair, Robert and Jason Lefebvre. â€œHead-to-Head: PHP vs. ASP.NET.â€ MSDN Academic Alliance. May 2003. <http://www.msdnaa.net/Resources/display.aspx?ResID=2315> (15 February 2004).