As a search engine optimisation programmer you tend to find yourself working with a number of different programming languages. The two most common server side programming languages that I tend to encounter are PHP and ASP. Having developed in both languages I feel that I can now comment on which language is the better of the two. So here it is; a head to head battle between PHP and ASP!
ASP is a Microsoft language and requires IIS and Windows to run. It is possible to run ASP on an Apache with an mod, but I have never really got it to work all that well. Also, because of the .NET framework that ASP requires when you install ASP on a Linux based Apache server you are effectively installing a crippled version of the system.
PHP will run on almost any web server and almost any platform. It is not a case of saying what PHP will run on, but more of what it won’t run on. PHP will even run quite happily on IIS on Windows with no problems at all.
PHP wins round 1.
To say "I program in ASP" is a bit of a misnomer. ASP is actually a set of languages that work through the .NET framework. When you use ASP you are using either JavaScript or VBScript or C#, this adds a further level of needless complexity. When you program in PHP you are doing just that, PHP is the language you are programming in, and the language you are programming in is PHP.
This is initially confusing, but it is even more so when you look at how Microsoft creates programming languages. Take the example of reading the contents from a file. In PHP it is a simple case of creating a pointer to the file, reading the contents to a variable and then closing the pointer. Even with all of the checking mechanisms to make sure that the file exists the code is still only four lines long and it works in every situation, no matter the content or format or location of that file.
In ASP it’s another story. You first have to pick from five different classes depending on what type of file you want to read from. Once you have the right class you only have to write three lines of code to get the content, but what if the situation changes? You need to rewrite the code with the correct class. Essentially PHP is maintainable, ASP is not.
PHP wins round 2.
I have always found Microsoft languages a little difficult to get into. They seem to have a habit of massively overcomplicating simple things and deliberately creating languages that don’t look or act like you would expect a programming language to act. I will agree that some PHP code is horrible to look at, but that’s just what the programmers have written. All ASP code is complete nonsense to many programmers.
Microsoft will write a program to do a task. That seems a simple enough concept, but when you have five thousand programs doing five thousand things it tends to get a bit complicated. So the code base for ASP is completely huge. PHP is written from a Linux point of view where every program has more than one function, so you therefore get 500 programs doing ten thousand things. This simplifies things enormously as you only have to remember a handful of functions for everything you need.
Microsoft also likes to makes things obsolete. Every time they bring out a new system they always panic the developers by rewriting most of it so that all of the old systems don’t work. PHP is always written with previous versions in mind, so that a program written in PHP3 can still run perfectly well in PHP5. Functions aren’t just thrown away; they are depreciated for a few major versions and then removed. This makes maintaining code much easier.
Lastly, the use of global variables in PHP is better than the ASP way of extracting the variable out of the Request object.
PHP wins round 3.
It can be said that the two major flaws in PHP are the register_globals directive and magic quotes. The register_globals directive is the way in which POST and GET variables are turned into server side variables on the fly. What this means was that it is quite easy to hack the system by forcing new variables onto the server. This has now been turned off as a default and you are strongly recommended to leave it off but there are still legacy systems out there that have this function turned on.
Magic quotes is a reference to what are called SQL injection attacks. Introducing this flaw into a PHP program is the fault of the programmer, but many programming novices will fall foul of this.
ASP has a notorious reputation with regards to security. Because of the complexity of the ASP model there are lots of different components to fail. The problem is that many do.
PHP wins round 4.
I would say that PHP is a lot more common on the internet than ASP. Look at the Netcraft web server survey and you will see that all of the servers available are able to run PHP in some form. If you just add together the servers that you assume to be running PHP you get above 50 %, which is still very high.
Also, most of the open source projects available (like Wordpress and OsCommerce) are written in pure PHP.
Due to the fact that PHP is so common there are a lot of resources out there to help programmers learn the language. A Google search for the phrase "php tutorial" gives me over 60 million results, whereas a search for "asp tutorial" gives me 25 million. From this it is easy to see which language is more common. This commonality makes the language easy to pick up and research.
PHP wins round 5.
PHP is written in pure C, so it is perhaps one of the fastest web based languages available. It is not as fast as perl, but that language was designed with a different aim.
ASP can be written in several different languages, which is one level of complexity. You language of choice is then translated into what is called Common Language Infrastructure (CLI) which is then fed into a virtual machine and executed. As a consequence the language is slow and messy.
PHP wins round 6.
ASP can connect to Microsoft SQL server and perhaps Access (with a major speed hit). It is possible to connect to other things but it is recommended that you only connection to a SQL server. Also, in order to connect to anything in ASP you need to create what is called a connection string. This string has to be the most complicated bit of text I have ever seen. Why they can’t just create a function and give it the correct parameters I don’t know.
PHP can connect to almost anything, again it is not a case of what PHP can connect to, but a case of what it can’t connect to. You can create a bunch of flat text files and use them as your database if you wanted to, PHP doesn’t really care. Speed is also not an issue when connecting to one database or the other.
PHP wins round 7.
To run ASP you need some hefty hardware that will set you back a bit, followed by the stupidly expensive software licences for Windows, MSSQL and IIS. Just getting up and running with an ASP server can set you back more than £10,000.
PHP is usually run on an Apache server running on Linux. PHP is open source, Apache is open source and Linux is open source so the start up costs include the hardware and nothing else. In hardware terms you can run a fully working PHP system on a 5 year old Pentium 3 with 128MB of RAM in a spare room in your house if you wanted to. I can guarantee that it would work because I have tried this myself!
PHP wins round 8.
When I talk to an ASP programmer about the sort of things I have written in PHP they stare at me like I’m a crazy person. PHP can do everything from page scraping to generating graphics with just a few simple functions. If there is anything that PHP can’t do then you can ask the operating system to do it for you using some PHP functions.
PHP wins round 9.
Out of 9 rounds PHP wins 9 and ASP wins 0. I think it is safe to say which is the better language. Either that or it proves which language I love!
However, I’ve yet to find anything in ASP that makes me think it is done better than PHP. There may be better language out there than PHP (Ruby seems to be making waves recently) but between ASP and PHP it is PHP that wins out every time.
Phil
Research and Development
Great article, I would say one thing though. I don’t think the cost of an ASP server is quite as high as 10 grand, maybe 3-5 depending on your setup. But still much better than linux which can run happily on the kind of hardware most companies would put in a skip!
Its so easy for php to win because ASP is so bloated, over complicated and deliberately proprietary.
Good article phil. PHP is always good in term of flexibility and robustness. But i have a problem with PHP on my ubuntu linux. so, i use windows to work with PHP developement.later i will do it on my linux.
[...] Hi guys, today, i want to share something with you all about PHP programming. I ve just read an article talked about PHP vs Asp .Net in JustSearch website and got impressed with it. It talked about comparison of PHP and Asp .Net. PHP is free but yet powerful. I like PHP programming since it free and we can find source code anywhere in the internet. does it sounds GOOD? Ok guys, if want to read the original article please click the link below. —>>>> Phil Research and Development [...]
I have always experienced faster browsing using an ASP/windows server rather than PHP/linux?
I’d just like to flame this article and point out some obvious flaws in the “argument”
1) PHP is a scripting language while ASP.NET (which you are referring to as ASP which is incorrect) is a TECHNOLOGY. If there was a PHP.NET equivalent guess what… you could make an ASP.NET site written in PHP!
2) The Mono Project allows .NET applications to run on Linux, Tiger OS and others. You didn’t mention that at all.
3) The statement “If there is anything that PHP can’t do then you can ask the operating system to do it for you using some PHP functions.” – is flawed. If there is anything that “ASP.NET” can’t do then you could also ask the OS to do for you.
4) The statement “To run ASP you need some hefty hardware that will set you back a bit, followed by the stupidly expensive software licences for Windows, MSSQL and IIS” – is just plain incorrect. MSSQL has a free version and IIS isn’t licensed. Additionally, you can deploy a website on XP Pro (not advised) negating the use of a WIN 2K3 license. Its not expensive.
5) The statement “A Google search for the phrase “php tutorial” gives me over 60 million results, whereas a search for “asp tutorial” gives me 25 million” – vauge. that could be 60 million pages where people are asking “Help, where can I find a php tutorial?” vs 25 million pages hosted on Microsoft’s MSDN Library site. You’re attempting to lie with statistics, and that’s not kewl.
6) The statement “…and deliberately creating languages that don’t look or act like you would expect a programming language to act.” – you mean languages like Basic?? The most user friendly language ever? as opposed to C/C++ which is crypt? C’mon
7) (This pissed me off btw) “It is possible to run ASP on an Apache with an mod, but I have never really got it to work all that well.” – just because YOU can’t get it to work doesn’t mean that it doesn’t work, in actuality it means that you’re incompetent!
Have a nice day!