C# vs PHP: The right choose


Let's start with a quick definition about the two contendents:
C# - An object-oriented programming language in development from Microsoft, which is intended to combine the computing power of C++ with the programming ease of Visual Basic.
PHP - A server-side scripting language designed for web development but also used as a general-purpose programming language.
As you can have already noticed there are plenty of discussions on forums and articles on the net and this is not making easy to understand the real potentiality and advantages of choosing C# instead of PHP and vice versa.
The main cause of this huge contradictory posts and comments mainly come from false beliefs probably without any real proof of what people are saying.
In this articles I will try to give you a complete overview of the two languages considering for both of them advantages and disadvantages, strengths and weaknesses, good and bad fields of application, just because the smartest, neutral and right answer to the question "what is the best one between the two?" is another answer: "What do you need the language for?".
To find the true answers for each aspect on our analysis we will use statistics... There is always a reason if 80% of developers choose a particular language to develop websites!

Desktop application

C# (according to Google) is more widely used than PHP to realized desktop application, the main reason is that C# can be compiled and allow you to create native graphical interfaces using the powerful Visual Studio tools.
PHP doesn't have any native interface features and cannot be compiled but day by day there is markets and technical revolution are strongly requiring a desktop application to became a web-based application, the reason is that web applications are more flexibles, natively cross-platform (client side), easily customizable and lighter than their executables versions.
In client-server architectures, the usage of a web application has huge advantages also for the upgrade management making possible to upgrade and apply changes only once and directly on the server, with deskop applications this is not possible unless you want to develop some upgrade management structures.
Considering what I said before C# is the right choice when executable compiled software is not an optional.

Web application

As we can see on Google most of the websites are NOT built over C# (ASP.NET), the biggest example of C# usage for successful websites is for sure Microsoft.com (obviously), StackOverflow and MySpace.
If we consider PHP we can see that mostly 90% of personal and corporate websites are built over it. 
The percentage drop down when we consider bigger websites that for many different reasons uses not only one language for all their websites functions.
For example, Google.com is built using C, C++, Go, Java and Python.
A good example of big websites developed in PHP we can find Facebook.com, Yahoo, and Wikipedia.
Choosing PHP for web application will be the right choice for performances and effort (in terms of development time and complexity).

Phone applications

Considering that most of the modern smartphones OS are developed in Java (Apple IOS, Android) this is the best language to develop applications that will run with the built-in runtime machine.
But since we want to compare C# and PHP we can say that C# gives you the possibility of building and compiling an application for mobile purpose.
Since a few years ago there was no possibility to develop mobile apps in PHP but now with the support of modern and ad-hoc frameworks you can easily build your PHP phone application, an example of frameworks, probably the most used is Apache Cordova even if the framework is less performant than C# (on modern hardware this is negligible).
Cordova will allow you to build an application with less effort respect C#, easily customize user interfaces but considering the performance side for an application that needs to use more calculation power, a smarter choice could be for sure C# (if you are not considering Java).

Costs comparison

Many people think (right or not) that C# is more expensive just because it's a Microsoft product and licenses cost impact on the overall development cost.
This is partially true, if you are starting to develop your own small website you will probably need to invest more money on it if you choose C#, Server OS licence costs if you want to use IIS as a web server (alternatively you could use MONO framework on Linux), Visual Studio licence costs (unless you use a community version but only for Personal use or free express version with limited functionalities).
In larger project where many developers are involved and where the cost of server licences is not impacting on the full cost you should anyway consider that you still need Visual Studio licences for each developer (you may save some money buying multi-license pack) but what really make the difference in the overall costs is time in development and time in performances optimization!
If you speak with experts in both C# and PHP development you will notice that it's required between 20% and 40% time more to complete a project in C# compared to the equivalent in PHP.

Database Management

99% of application nowaday make use of a database to store and retrieve information, to help developers in building communicate with databases both languages have abstraction layers for data management but for sure there is a wider and powerful choice in PHP.
C# mainly used are LINQ, EntityFrameworks, and NHibernate, if you consider building a performance effective solution LINQ is the better one even if it's not real abstraction layer (native query language).
PHP equivalent to LINQ is PDO but if you need a more structured a featured abstraction layer you may consider Doctrine or Propel for example.
In another article, I will talk more in details about Database management explaining more in details the difference between DBAL (Database Abstraction Layers) and ORM (Object Relational Mapping).

Community Support

The last but not list argument that I want to address is the fact that every PHP engineer makes: "The PHP community of developers is bigger than C# / ASP.NET".
Yes, there are more PHP developers than C#.
The PHP community has a lot of people behind it but they are spread out among all of the PHP web frameworks.


In general, PHP is more suitable for web application development, it is easier to write PHP code for web based applications. PHP has been written mostly in C so it is pretty easy to extend it and build modules for your needs.
ASP.net is more complicated due to the overall NET architecture and its C++ inheritances. On the other side provides lots of generic functionality (you don't always need, but might save you when the unexpected happens).
You probably will need to compile it every time when debugging and developing and this could cause a huge time loss compared to PHP that being interpreted has a powerful and quick debugger.
In whole, PHP's OOP ( 5.3 or newer versions) can definitely support large scale applications, large code base, it has some performance and memory issues, but it is just the cost of a dynamic language, and there are solutions out there but even ignoring the optimization aspects performances are quite better than C#/ASP.NET.

Read also..