views:

6006

answers:

11

I was asked yesterday by a client whether it was better for him to run his high-availability / throughput shopping site on ASP.net or PHP. He's ready to make a "Ten Year Decision," so he needs to know that the platform he picks will continue to be well supported and that developers will be available with the skills to work on it.

I've got to say I was stymied by this question; I work regularly with both platforms and I honestly couldn't make a judgement.

Here's my opinion:

ASP.net is a comprehensively well-supported and maintained platform, utilising a dynamic and powerful language. However it is continually being overhauled and updated; with every passing season a new technology or methodology is implemented (eg. AJAX, LINQ and MVC) and developers are constantly forced to play catchup. Stop using ASP.net for six months and it'll take another six months to learn all the new techniques that have come out. ASP.net is closely coupled with Microsoft's server platform though, so performance is optimised right down to the server level and it does present the opportunity of creating compiled components that could radically improve performance.

PHP is designed solely for one purpose; to run scripts on web servers. It is very stable and efficient and the language itself is easy to work with. It is open source so it is not driven by market imperatives and the overall structure of the language does not vary greatly from one point release to the next. As far as I know the only really major changes came between PHPs 4 & 5, with the introduction of better object support and the PDO database library. It is lightweight and compact and should scale easily.

In terms of future-proofing and developers, it's my opinion that PHP developers are easier to come by but that their skill sets vary considerably from one coder to another. ASP.net developers generally tend to cost more but they could well be more manageable and predictable. The platforms themselves will continue to evolve; ASP.net more rapidly and radically but it may reach a point of stability where it's largely complete and static. PHP is probably already at this point and changes to the language itself will be fairly minor over the next decade, mostly taking the form of security improvements and performance efficiencies.

So, I still have no idea what to recommend. I think each has their pros and cons. I don't really like asking such open questions as this but I really value the opinion of the Stack Overflow community and would like to hear what it has to say.

A: 

I don't know about ASP.NET, but for sure PHP has major security issues.

Because it's open source there are too many people just sitting and analysing code to find bugs (with success, like buffer overflow in add slashes).

Another issue with php are php developers. There are probably many experts out there, but out of those that I've came across (maybe around 100 or less) only few really knew what were they doing and why. Even the code that I've seen in php books has issues with security.(like you can do SQL Injection there or xss or sth. else)

Maybe ASP.NET has the same issues, but I'm not aware of them.

kubal5003
Foolish response. The fact that it is open source makes it more secure. It's also laughable to conclude that LAMP stack developers are somehow less sophisticated than Microsoft stack developers. Which one has the lower barrier to entry for christ's sake?
BC
You can screw your security equally well with ASP and PHP.
Jenea
both issues of security and competence are present in... wait for it... ALL development environments. you can leave gaping holes in the security of every application, regardless of programming language. you can also expect to meet only few who are *very* good. Examples: **with php**, a lot of developers are originally web designers, so their OOP is not polished. **with .NET** a lot of developers are basically guys who drag and drop most of the application. **with java**... well... not enough space to describe the bottom of THAT barrel :) genius is everywhere, mediocre is everywhere too.
Nir Gavish
I didn't say ASP.NET doesn't have the same issues ! I said I don't know !! I know way too many issues with php security so I thought it's worth commenting. And: "The fact that it is open source makes it more secure" just looooooool. You just have no idea.
kubal5003
:D you must be having some personal issues with PHP then or you don't know PHP at all. It is an equivalent and capable technology.
Gaurav Sharma
@kubal5003: There is plenty of independent research that does prove that open-source software is more secure. While, yes, everyone has the source-code, and yes, it is easier to find security flaws, it is as easy for developers to review their peers code and fix those flaws. Plus, response time is way higher on OSS than in propitiatory platforms. Also, the security issues you do describe on PHP are the fault of the developer making his code, not the platforms. You can have the same flaws in any language if you don't know how to use it. It's not PHP's fault that so many idiots is using it.
Andrew Moore
And just as an example, the Chromium browser is OSS, yet it was the only browser left standing after rather lengthy security competition. The second best browser during that competition was Firefox, which is also OSS by the way. Absolute worst? Internet Explorer, proprietary software.
Andrew Moore
argh
Maybe there is plenty of independent research that does prove that open-source is more secure, but show me JUST one HA and critical service that is based on open source. Even if companies are using linux then it's red hat or some other distribution with support and that is maintained by some company that you pay for being sure.@phpI've just seen too much of it. Issues with php are definitely not only connected to foolishness of developers. The one that I've mentioned - with addSlashes is in the newest version so don't tell me it's sooo great.
kubal5003
Don't believe me? http://www.h-online.com/security/news/item/Pwn2Own-2009-ends-Smartphones-Chrome-unbroken-740707.html Next time, before stating ignorantly that OSS is less secure that proprietary systems, bring proof. The fact that its source is available to everyone is exactly what makes OSS so resilient to security flaws. They don't stay undiscovered long, and they are usually fixed within a day (which is far from being the case with proprietary systems).
Andrew Moore
argh
@kubal5003: 1. `addslashes()` is not meant to be use to escape security sensitive information. 2. Plenty of big websites (Yahoo, Facebook, etc.) uses PHP without any issues. 3. Critical services? There are plenty of companys whose intranets, B2B and CRM systems are running on PHP. It will be extremely hard to provide examples as such systems are inertly closed. 4. Companies using Linux that pays, they pay for SUPPORT. They get the same security as everyone else.
Andrew Moore
@argh: While yes there is more in-the-wild security flaws for IE simply because of its popularity, that's beside the issue. The OPs says that because software is OSS, it is less secure. IE is a great example of a compromised proprietary system. Also, during Pwn2Own, all browsers are treated equally... So why were less flaws discovered in Firefox, for which the source is available, then IE in a competition where all browsers are given equal importance?
Andrew Moore
@kubal5003: And you keep bringing that `addslashes()` vulnerability when it was fixed in 5.0.3, which is far from being *"in the newest version"*. Send me a security advisory proving me of the opposite instead of pulling vulnerabilities out of your behind.
Andrew Moore
ASP.NET is far from being bullet proof either: http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=ASP.NETAnd personally, I find it way more dangerous to use a closed platform with few known vulnerabilities than an open platform, which gets vulnerability reports every month. At least on the second one, the vulnerabilities get public and fixed rather quickly, while on the first one, you can get attacked by a privately discovered flaw and no-one knows...
Andrew Moore
The 'many eyes' philosophy that is touted to keep open source safe is nonsense. People behave almost exactly the opposite way in real life situations. But it's nice to see that enough people have been suckered into falling for it to show up in waves to give a -8 to an at best mildly inflamatory answer.
quillbreaker
@quillbreaker: Yet there is independent research which proves, beyond any doubt, in a time span of 15 years, exactly the opposite. How do you care to explain that? Open-source software does have a higher flaw discovery, quicker flaw discovery, and quicker turn around on patches. Of course, open-source software used/supported by a small community is more vulnerable than closed-source software. But when a project is actively maintained by more than 70 people, research proves that is becomes way more secure than their closed-source counterparts.
Andrew Moore
@argh: So because college idiots with no knowledge of security whatsoever codes in PHP, it makes the language less secure? It makes their code less secure, not yours. And I'm glad you linked to that MySQL bugs page. See, all those bugs are probably already fixed in the nightly build, holes patched (the security related ones, not functionality). All you have to do is update your software. During that time, someone is hacking your Microsoft SQL Server, and Microsoft doesn't even know the flaw exists! FANTASTIC!
Andrew Moore
@Andrew So all open source projects with less than 70 people maintaining them are rubbish from a security perspective? Thanks. I was looking for a number on that. Now I know that 99.9% of open source is rubbish from a security perspective. Good to have worked that out.
quillbreaker
@quillbreaker: I must personally congratulate you on your lack of perspective, openness and common sense. You know far well this is not what I meant and that number, as stated in the research, is just an average found using scientific research methods. Each OSS project should be analysed on a case-by-case basis.
Andrew Moore
With open source I think there is one more thing that is worth mentioning. It's always said that "you can check everything" and that is true, but only for small projects. With projects like mysql, php, NHibernate or even quite small projects like AnkhSVN the issue is that in reality you CAN'T, at least if you are not willing to spend half a year on checking.
kubal5003
@Andrew You're right, my scope is off. Let's focus a little more. You assert that PHP is secure because there's an awesome 70 man team working on it and checking the code for security holes on a routine basis. Let's say I grant that. Do you think that Rob can guarantee that 70 people, or in fact any people at all, will be working on PHP in ten years?
quillbreaker
@quillbreaker: Can you guaranty that Microsoft will still support ASP.NET in 10 years? Considering that mainstream support of a Microsoft dev product is 10 years, I say that the answer is exactly the same as your PHP question. http://support.microsoft.com/gp/lifepolicy
Andrew Moore
With commercial software you pay a company for a package, and you and the other people who buy that software have an expectation of software which works, and you can seek redress in the courts if the software is defective. You get what you pay for.With open source, you get what somebody else pays for. You have none of the rights you have in the first scenario, and no assurance that they will continue to pay.It's your call. You'll probably be fine either way.
quillbreaker
@Andrew "See, all those bugs are probably already fixed" PROBABLY - I loled, sorry dude but your attitude is of a fanboy and you don't seem to see the 'big picture'. Listen to stackoverflow's recent podcast about OS. OH! Almost forgot! Stackoverflow is written in asp.net... hmmm... let's find a security hole! ;) Take it easy, cheers.
argh
@argh: Actually, I hate MySQL. I don't like the platform, I don't like the mentality, I don't like the Sun takeover. Take a look at PostgreSQL and see if they take security seriously. And I never said that closed source software are more prone to security issues than OSS. They are just more prone to undisclosed security issues than OSS. I personally would rather use a system with security issues being publicly disclosed and fixed rather than a system where the issues are kept under wraps and where changelogs only have a vague notion of "some security issues were fixed".
Andrew Moore
@argh: (continued) I'm not an OSS fanboy. I develop in ASP.NET and PHP equally and I love both platforms. They both have their merits and their flaws. Security isn't one of them. Developer education is a major flaw on PHP's side, and is the reason why it has such a bad reputation. Competent developers using PHP are producing secure code. Incompetent developers using PHP are producing swiss cheese. The same applies to ASP.NET. Unfortunately, incompetency seems to be a trait shared by the majority of PHP developers, but in the end, **it doesn't affect my code**.
Andrew Moore
+3  A: 

Try to put yourself in the shoes of a developer maintaining code written 10 years ago on both stacks. For PHP, you'd be looking at PHP 4.0, only one major version older and very similar. For Microsoft, you'd be using ASP classic 3.0, which is a far, far cry from the .NET 3.5 platform of today.

I would wager you'd be looking at a similar situation in the year 2020.

BC
You really can't make that comparison. The things ASP Classic and ASP.NET have in common is not much more than the three letters A, S and P. You could equally well compare ASP.NET to PHP 4.0. If you're going to compare ASP.NET 3.5 to an older version it would have to be ASP.NET 1.0.
Oscar Kilhed
You just made my point for me. They are very dissimilar. Different disciplines, even.
BC
I'm really not sure what the point is, how can you compare 10 year old software? You can also look at it the other way and see how .NET has evolved and how much PHP has stagnated as it's the only 'web language' without a well established 'web framework'.
mythz
Comparing ASP with ASP.Net is like comparing PHP with JSP, really. Compatibility level between ASP.Net versions (and .Net versions in general) is high, and the upgrade process is easy. New features are opt-in. (see also my answer)
jeroenh
In 10 years, nobody may be supporting PHP at all, or perhaps not sufficient people to provide necessary product quality.
quillbreaker
@quillbreaker: In 10 years, nobody may be supporting ASP.NET at all, or prehaps not sufficient people to provide necessary product advancement. This little argument of yours can go both ways. If Microsoft drops support for ASP.NET towards something else, its endgame. Same can be said about PHP.
Andrew Moore
+2  A: 

I'm a .Net developer and this answer might be a little subjective

ASP.NET Has a set of class libraries , Great(well almost) tooling , there is also the support and ASP.NET code is compiled(some performance gain)

PHP is good to easy to use and free (All you need is a text editor and LAMP)

Both has been out for a while so there is plenty of resources out there if you encounter any problem. anyway i would really look for what your client need

one more thing in software development things change in months if not days so it is hard to make a 10 years plan

Yassir
+4  A: 

PHP will most likely not change as much as ASP.NET and the other technologies connected with it in the coming decades.

Generally, PHP has a larger community than ASP.NET and is also used or available almost everywhere today. That also means that there are probably more resources, libraries, frameworks, etc. you can choose from. I don't know if that really counts for your client, though.

lamas
Saying that "php is available almost everywhere" is a bit of a strech. If you are leaving in Windows world php is a rarity
argh
+8  A: 

Well, having spent 100% of my professional career divided between the two technologies I have to say that it is an almost impossible choice.

Both are proven web-technologies that have been around for a long time. I guess my choice would be based on the availability of trained and qualified personnel.

Personally I think that ASP.NET's greatest fault is the fact that you loose control over the generated output and that ViewState can quickly get out of hand. However ASP.NET MVC seems to be alleviating that situation somewhat.

With PHP your code tends to get quickly out of hand, at least if you are not careful.

Personally I think I would prefer a scripted language over a compiled language for web work. I would suggest looking very carefully at Ruby On Rails.

ASP.Net - pros:

Backed by Microsoft. Visual Studio (though you need super computers for acceptable performance) Plenty of third party tools available, though mostly at high costs. C# is a good statically typed language (excluding generics). There is a MVC framework available.

ASP.Net - cons:

Microsoft platform needed for deployment. Vendor lock-in. ViewState is hard to manage and get right.

PHP Pros.

Duck typed language Large library of addons - mostly free Can be served from a unix platform

PHP Cons:

Object model is somewhat "exotic" Might be harder to find qualified programmers.

These are just my personal thoughts on the subject. You really have to look at your circumstances. Does your company have a lot of trained windows people to manage servers and the like, then I'd go with ASP.NET.

If you have linux/unix expertise then php or RoR becomes a no-brainer for me personally.

Good luck with your choice.

Michael Wulff Nielsen
Excluding generics?
Joel Mueller
C# supports the creation of runtime types through generics. For instance you can declare for example a "List<String>" objects. I personally prefer ruby/php style where you can combine datatypes as you please. For instance this is simple in ruby:temp = { :bar => 'foo', counter => 1 }In C#:Dictionary<string,object> temp = new Dictionary<string,object>();temp.Add("bar",(object)"Foo");temp.Add("counter",(object)1);I know which one I find easier. A lot of things that can be done with a simple hash i ruby needs a class or a struct in C#.
Michael Wulff Nielsen
That's because having to put completely different things in a dictionary is HORRIBLE design practice. C# is not a dynamically typed language. Don't point to something a language does because it's dynamically typed and then claim this is a failure of C#. All dynamically typed languages have this characteristic. EDIT: And that class or struct in C# is what _makes_ the language statically typed.
Billy ONeal
@Billy you are completely correct as to why C# is not a dynamically typed language. But I disagree with you on the design practice. I didn't mean to imply that C# is a failure, because it most certainly isn't.I was trying to point out why I find languages like Ruby easier to work with. This is of course my personal preference.We could discuss static vs. dynamic typing for a long time, suffice it to say that both models have been around for a very long time and they both seem to work.
Michael Wulff Nielsen
I understand that. I'm just saying that the fact that you can't put any old object into a generic is what makes C# strongly typed. If it didn't work that way, it'd be dynamically typed. I'm not saying one is better than the other, but the fact that you can't put any old object into the dictionary is what makes it strongly typed. If you're saying that it's strongly typed excepting generics, then you are 110% incorrect.
Billy ONeal
I agree, you are correct with regards to typing. I was trying to point out a somewhat overlooked feature in C# that actually makes a lot of sense.
Michael Wulff Nielsen
This discussion in the context of C# 4.0 might look somehow different.(if it was unclear: they introduced dynamic typing in C#)
kubal5003
+1  A: 

10 years is more a couple lifetimes for any web app, that's kind of unrealistic. But you can still find old HTX/IDC scripts and crusty VB CGI executables puttering along if you know where to look, so honestly either will probably be okay.

PHP might be more okay though - right now you can download & compile PHP 3 from here, set up Apache 1.3, and watch it spit out pages exactly like it did a decade ago. Finding commercial/third-party support for it will be painful, but still possible - everything you need to recreate a 10-year-old web server is all right there in plain view.

With a language & framework that are tied to a closed OS, which in turn is tied to security hotfixes that can't be ignored, you might have a harder time of it. IIS still handles "classic" ASP and .NET 1.0, but should MS decide to pull support for them 10 years from now because fundamental changes in .NET XIV require it, you might end up stuck between a possibly insecure server and praying you never lose the old install disks. (then again, there's also Mono)

Still, 10 year lifespan for a web app... that's a long time, things continue to change too fast to guarantee anything on the web will last that long, including the web itself.

tadamson
`and watch it spit out pages exactly like it did a decade ago` haha
sandeepan
+1  A: 

The platform is way less important than the people working with it. I'm biased towards ASP.NEt personally, because I know the platform a lot better. But I also know that an improperly designed system WILL have to be trashed and rewritten at some point, simply because the code base has become a nightmare to maintain.

A well-designed system, based on proven patterns (MVC comes to mind, but an MVC application implemented by unskilled developers can be worse than a webforms app written by people who pay attention to proper design, code quality and maintainability).

From personal experience, I would state that ASP.Net, being part of the .Net platform, has more opportunities when it comes to writing solid, object-oriented code. In PHP, Object-Orientation seems to have been glued in as an afterthought.

But as I said, I'm obviously biased. I'm sure that well written systems in PHP can be equally maintainable (and survive 10 years).

jeroenh
+16  A: 

I would choose my language not on raw numbers first, but on your functional requirements. If after analyzing your functional requirements you do not have a clear winner, consider the following points:

(Disclaimer: I develop in both PHP and ASP.NET on a regular basis)

Future-proof

None of both platforms will disappear soon. As for each major versions of each platforms, they might come with some changes that will break your code.

Performance

Performance wise, ASP.NET is faster than PHP (for those who needs numbers) because of the typing scheme and other languages choices (this is discussed in a SO Podcast but I can't seem to find the link). But you also need to consider that PHP is less costly to paralilize than ASP.NET. You do not need to purchase software licenses for each and every single server (unless you choose to use Mono for your ASP.NET).

Security

PHP has a bad reputation security-wise and I can understand why. There are a lot of students and hobbyists who started coding in PHP and have absolutely no idea of what code security means. Please remember that this affects their code, not yours. Also, if you choose PHP, be careful when choosing third-party documentation. A lot of them a written without any consideration for code security and their examples are riddled with security issues (especially the database section of such books).

There are equal opportunity to shoot yourself in the foot in ASP.NET than in PHP. There is nothing stopping me from writing the following code in ASP.NET:

// DON'T DO THIS
string statement = "SELECT * FROM Employees WHERE EmployeeName = '" 
                   + employeeName + "'";

SqlCommand command = new SqlCommand(statement, connection);
SqlDataReader reader = command.ExecuteReader();

as there is nothing stopping me from doing the same in PHP:

// DON'T DO THIS
$statement = "SELECT * FROM Employees WHERE EmployeeName = '"
             . $employeeName . "'";
$result = mysql_query($statement, $connection);

Yet we all know that we should never do anything as such in our code.


Whatever language you choose, follow these simple security rules. Those are applicable on all platforms.

  • Use parametrized queries
    ADO.NET has built in support for them. If you are using PHP, drop php_mysql and use the php_mysqli extension instead (or even better, PHP Data Objects) which has support for parametrized queries.

  • Never trust user input
    Never trust user input, even input that isn't meant to be changeable. Learn to expect unexpected values like \n in <input> fields or values which are not even part of your <select> and deal with them accordingly.

  • Validate, validate, validate
    Always validate your data. If your data has been validated in a previous step, validate it again. User can't get to this page without logging-in? Validate his login information on page load. Ties in with the rule above.

  • Escape, escape, escape
    Always escape your HTML output to prevent most XSS attacks. Even if that field is only supposed to carry a number. Creating a file based on user input? Escape and validate the file name. Passing to a CLI application? Escape your shell arguments.

  • Follow best practices, not common practices
    And in PHP's case, best practices can be in total discord with common practices. Learn to differentiate between the two. Turn off magic_quotes, don't use addslashes() for security purposes, etc...

  • Protect sensitive information
    Don't store plain-text passwords in the database. If you need the original value, encrypt. Most of the times you won't, so hash. Also, you really don't need to fetch that SSN value from the Employee table if you are displaying a directory of employees for phone purposes. Sensitive pages on your website should be protected being a login page.

Andrew Moore
+1 Excellent points. These apply to any language on any platform.
Grant Palin
A: 

I started writing this as a comment to BC's answer, but ran out of characters :-)

BC is right that ASP.Net has evolved, but that's more a plus than a disadvantage. Upgrading an ASP.Net application is generally rather straightforward: there are very little breaking changes between platform versions.

First, it's not fair to compare ASP with ASP.Net here. That would be the same as saying that it's hard to move to ruby on rails to php.

Between .Net versions, the compatibility level has always been really high, and the breaking changes are generally well documented. From experience, I can say that most applications written for .Net 1.1 will work 99.99 % sure without any modification to the code. Also, the tooling (Visual Studio) fully supports the upgrading process. Obviously, new versions bring new features (LINQ comes to mind), but those really are opt-in: you use them when you're ready and if there's any benefit in using it.

jeroenh
+1  A: 

I'd like to chime in some things that has not come up in here. You mention "high-availability/throughput", so I take it that is important.

I agree that PHP itself is slower than most other languages when it comes to algorithms (cpu bound), but most sites are mostly I/O bound (file and/or database) anyway. So unless you are doing stuff that is cpu intesive (shopping cart is not...) you should not concert yourself with cpu bound performance issue as that is probably only a few percent of the whole request.

The LAMP platform really shines when you need load balancing with multible web servers and databases, file access, high availability and stuff like memcached.

Also, I think that you cannot really choose between ASP.NET and PHP. What you are choosing between is in fact ASP.NET and LAMP (P=php). That is more than just selecting a programming language, considering you will be using Linux instead of Windows, Apache instead of IIS, MySQL instead of MSSQL etc. That may be quite a step for some people.

So you really should spend some time looking at what kind of site it is and what the requirements are regarding availability and scalability and from that select one of the platforms.

Martin Wickman
+1  A: 

As a former MCSE and now company owner, we've deployed Microsoft technologies for years.

Most companies we worked alongside starting using linux for webhosting so in the early 2000s, we deployed our linux server with PHP & MySQL. We hired a PHP, MySQL, JS coder to deliver our solution...since deployment, we've never had one single security problem or performance issue since.

From this situation, we've come to understand this. We hire coders based more on their solutions not primarily on their systems...A coder that understands potential security risks, the environment it will operate in and the needs of a client is more important than the whole this vs that argument. At the end of the day - a language is just a tool and software solutions are made by people for people.

In our situation, we employed a great coder who delivered a great solution - it just so happened that the PHP, Linux, MySQL solution worked really well, was secure as hell and stable...and to top it off, it was a lot cheaper short-term and long-term.

Times are tough for everyone now, and gone are the days of big I.T. budgets - Microsoft don't seem to understand this and are still intent on smacking us all over the head with massive software infrastructure and education bills.

All of our companies now look outside of the scope for solutions that deliver the same scale but that don't kill our budget.

So we say more power to open-source solutions.

Bryan Hill
that's a great answer and you are absolutely right. It's always down to finding the right solution to the problem at hand, not trying to shoehorn the problem into a solution that you just happen to have available. I've seen this attempted many times (usually down to the limitations of the developer's own experience) and I've rarely seen it succeed.
Robin Layfield