Comparing the two development tools alone makes no sense. Because the two have their own strengths in their own development fields, it is like comparing Java with. NET, each having its own advantages. The main purpose of this article is to compare ASP. NET and PHP, so that you can better understand the differences between the two, so that you can choose your own development tools.
My daily work uses ASP. NET, the previous paragraph would like to learn about other network application development technologies. You can choose popular Ruby on Rails or Python, but you have limited energy and can't even learn it, my blog is built on WordPress, where WordPress is written in PHP, so I chose to spend more time learning about PHP.
The biggest essential difference between PHP and ASP. NET is that PHP is only a programming language, while ASP. NET is a platform.
About 1/3 of the world's website applications are written in PHP, and most of these PHP programs run on Apache. As a language, PHP does not have to run on Apache, PHP is independent of the running platform and can also be run in IIS. Unlike PHP, ASP. NET is a platform rather than a language, ASP.. NET programs can be written in C # Or VB. NET write, can be compiled into any. net clr run on the programming language to write, ASP. NET is usually run on Windows + IIS, but it can also run on other Web servers, such as Apache.
In this sense, PHP and ASP. NET is like the difference between iPhone and Windows 7. It is not the same thing. But if you select one of them, you can choose one style.
However, as a tool for developing network applications, there are two significant functional differences in my experience.
Share-Nothing Architecture
The philosophy of PHP is Share-Nothing Architecture. Every HTTP request processing is independent and does not Share any data. If you really need to Share data, it is also through the file system or database, memory objects are not shared in the PHP runtime space. This article on Share-Nothing Architecture introduces Share-Nothing Architecture in detail, which can provide better Scalability and Maintainablity ).
Share-Nothing Architecture can be implemented using ASP. NET. The problem is that the programming language features of the ASP. NET family make it too easy to break the Share-Nothing Architecture. For example, if the static variable in C # is used, each HTTP request of the same AppDomain shares the same data, so it is not Share-Nothing.
Asynchronous Programming Model
ASP. NET has a function that is not available in PHP, Asynchronous Programming Model (APM), Asynchronous Programming Model. This Model can more effectively use threads and improve Scalaibility. Of course, writing asynchronous programs is much more difficult than writing synchronous programs.
PHP does not have Asynchronous Programming Model like ASP. NET. Why is the PHP world inferior to Microsoft technology in this respect?
I can answer the following two questions: first, Microsoft supports APM because it supports APM, and second, because Microsoft must support APM.
To support APM, you must have underlying support. As a platform, ASP. NET can use Microsoft's IO Completion Port to implement true Asynchronization. However, a programming language like PHP is only a programming language. It cannot be assumed that it runs on a platform that supports asynchronous ports. Therefore, it is decided that the language will not add the APM function.
Why does Microsoft have to support APM? On Windows, the process costs a lot, the thread cost is better, but it is still very large, so to effectively use the thread, you must create something like APM. In contrast, the cost of process threads on Linux is much lower, so that the pressure on creating APM is much smaller, and the efficiency can be maintained without APM.
Trends
This article is titled "PHP vs ASP. NET". Let's use Google Trends To see the comparison between the two. Look at the short-term PHP and ASP. NET is interesting. Every weekend, there are only a few searches for these two keywords. We can see PHP and ASP. NET users mostly work from Monday to Friday.
We can see that PHP search is declining over the long term. How can this happen? I cannot understand that PHP is still the most widely used network programming language in the world. Recently, Facebook developers have released HipHop, which will greatly improve the performance of PHP applications, the running speed may be higher than that of ASP. NET is faster.
Here, we will refer to a blog by Lao Zhao from the blog "talking about the PHP Execution speed comparison of ASP. NET".
I published a piece of news on InfoQ, summing up three articles on ASP. NET and PHP performance comparison posted by Joe Stagner on his blog. In fact, writing news is quite uncomfortable, because it cannot be mixed with personal opinions and can only be tiled and directly stated. Of course, if we say "another way of saying" like some news, we can cheat some "people who do not know the truth", but this is against morality. Therefore, after objectively presenting the news content, I can only choose to put my thoughts, comments, and other content on my blog.
Joe Stagner has a special background. He is an old PHP user. He was a heavyweight PHP developer before ASP. NET appeared. I don't know which day he joined Microsoft, so we can see it in some articles and videos about ASP. NET AJAX. This time, he has another sensitive topic: performance comparison. You need to know that every comparison will cause a debate ...... I don't want to use the "war of words". I think it is different from the nature of the "argument. Joe also admitted that every time he speaks PHP well, he will be accused by Microsoft's colleagues, and the PHP camp will say ". NET good" is Microsoft's trust.
I believe that excellent technical staff are both faithful and technically inclined. So it's really embarrassing for Joe to be in the middle. However, I believe that there is no conflict between faith and objectivity. Faith involves a tendency, while objectivity means a way of doing things after a tendency.
As for the comparison results, you can take a look at the news. In general, ASP. NET is significantly ahead of PHP in terms of pure execution efficiency. This is not surprising. One is to compile the code into a machine code execution method, and the other is to parse the execution and cache the op-code immediately, not the machine code). The performance is naturally far away.
Joe knows that it will lead to debate, so he wrote after the article:
I know that some people will be irritated by the test results. comments and objections are welcome, but if you are not polite, I will delete your comment and block your IP address.
If you don't like it and refuse to accept the result-you can test it as well. Use data to support your opinion, use my code or your own, and then argue over the facts.
Naturally, Joe also describes the test code and test environment.
The comments in the article are naturally very insightful. There are many saying that vs ide is good. Some people say that PHP can always write semi-professional programs. Joe responded one by one. I personally think the response is still very objective and closely centered around the test center. He said that although VS is excellent, PHP also has a good IDE. Whether a professional program can be written is determined by people rather than PHP. If there is an ugly PHP program, it can also write well-rounded code like C ++.
On the surface, ASP. NET wins PHP in terms of performance. As a loyal ASP. NET user, I should be very happy to accept this "result ". However, I don't pay attention to this because the pure speed of running is really insignificant for a Web application. For example, how PHP experts respond in Joe's third article:
ASP. NET's leading performance won't have any impact on me. PHP is my favorite, and my applications are fast enough.
Yes, ASP. NET is faster in terms of basic performance, but my applications can supplement this part of performance through excellent page implementation and JavaScript practices.
I am developing Drupal, and I am most familiar with PHP, so I would rather spend more hardware to maintain better development efficiency.
And a comment on InfoQ:
Convenient WEB development and flexible combination with various systems. Similar to glue, python assembles various objects and presents them to the Web. (python has done a great job in this regard ). This is the essential reason why PHP can be used today.
Previously, I criticized Java as a low-productivity language with a lot of responses. There are also similar statements, such as the open source and many projects on the Java platform. That's right. I have already repeatedly stressed this before launching the Java language. I agree with this point of view-but if this "conclusion" is true, it cannot be said: "Because the Java platform has many open-source and many projects, the Java language is not an enterprising language ". This is like some people say that "he is familiar with PHP and has many PHP projects, so PHP performance is faster than ASP. NET", confusing the two things.
The strange thing is that Joe didn't let people not use PHP, and I didn't want people to use the Java platform, but I have always suggested that someone else use Scala to replace the Java language ).
Many Chinese technical staff always have such a "fault", so they cannot use things on their own ". Since I am a Java platform developer and I am using the Java language, I can't tell others that the Java language is a bit bad. In fact, to do technology is to make a balance. "no silver bullet" means that no technology is perfect. We choose technology as the result of balancing between advantages and disadvantages. Only by recognizing the shortcomings can we draw on the strengths of other technologies to make a better balance.
Therefore, I have always recognized that SQL Server is indeed expensive and data storage should be on the * nix platform. Select more and have more performance.
Of course, this is not a problem for Chinese technicians. It is a wide range of problems. Coincidentally, Mr. Li xiaolai wrote a blog post yesterday, and it seems that he just talked about this issue. The article is very short. The full text is excerpted:
No matter who you are, you will always "choose" in your life. No matter how much you choose is true, how much is an illusion ). Everyone is trying to select the "best" Among the many options. There is a 2n choice in your life, and there is only one path to your own.
People may have two attitudes towards other possibilities on the way they are walking: "curious"-usually expressed as "regret" because they are dissatisfied with the status quo "; or "conceited"-this is the final choice for more people, because the "regret" expressed by another choice is generally considered negative, on the contrary, "No complaints, no regrets" seems to be more justified and determined, although not always correct ).
After a long time, people will unconsciously equate "I have been trying to select the best" with "what I choose is good, in this case, we assume that "a different choice from my choice is not good", and then we further evolve to "since the choice is not good," he is either stupid, it's either 'bad'. It's different from me!"
The root cause is here. Self-centered, over-Narcissistic, and out-of-the-box, out-of-man, and narrow nationalism.
There is another problem. I have talked about it many times before. It is too easy for domestic technicians to despise it. For example, in this news, more than one user thought this test was boring. Why is it boring "? This experiment may be meaningless because "this performance is not critical. I would like to say that the most boring thing is not the person doing the experiment, but the person who is entangled in the experiment results. Or, boring is not an experiment, but an experiment result. In contrast, I strongly suspect that people who think this experiment is boring are really concerned with "who is fast and who is slow", rather than the content expressed in the process and results. Don't speculate, don't think. So where can we find the basis for decision-making? It should have been bored.
These articles by Joe, as well as my summary, deliberately detail the testing process and the results beyond "running performance. In addition to being fair and objective, they are also important data. For example, I now know that the implementation of the driver for accessing MySQL on Windows is poor, while the performance for accessing PostgreSQL on different platforms is almost the same. I know that large file Copying on Windows is affected by ACL and the performance is poor. If you are interested in running PHP on Windows, you can get more information.
I don't know if it is a relatively high level of technical personnel in China, and it is easy to feel bored in some foreign discussions. For example, when someone talked about the native type of Java, someone replied, "Is it a financial crisis ". The last time someone talked to someone about the abbreviation of the ppt, they wrote an English letter to the software's original editor for verification. The foreigner answered this question in great detail, the difference between Abbreviation and abbreviation is also corrected. The author posted the letter and wrote a blog. The comments on the original site agree. Repost comments and click it all to scold the author for being idle.
I don't know if this is an academic attitude, or can I just say "I'm not enthusiastic about my work, I'm not curious about my life "? In the article native type, a friend replied:
The seemingly boring debate of Westerners has brought them to the height of today's day. The argument about whether everything can be expressed by rational numbers is about what sports are, debate over whether the Earth is the center of the universe or whether the sun is the center of the universe, how Satan was born, and how planets run. However, we only pay attention to practicality, so we cannot reach the theoretical level of the West. We can only wait for others to finish the debate and get the result. This is what we use.
However, people who are bored by foreigners often have no technical skills in China. Isn't it strange?
Similarly, Joe Armstrong, father of Erlang, writes Why OO Sucks; Stephen Schmidt writes Clojure vs Scala ON and OFF). James Strachan, founder of Java platform language Groovy, thinks Scala is a substitute for Java in the future, he and JRuby's core maintainers James Gosling and Charles Nutter on Scala. java is a great topic. These are all criticism of a thing, or the "boring" topic of "Language Comparison. So are they all idle?
I was wondering, if I translated their articles and published them with a name, or if I asked girI gala to publish them in a "public criticism", would they be accused of being ignorant of OO or Java? Don't say that, I have seen such a thing. Who often leave no source for domestic translation reprinting?
In fact, this is a logical problem. It is similar to the article "common logical errors" that mentions "personal attacks and 'you are the same", that is, they do not care about the problem itself, instead, it transfers arguments to the other party. In fact, is a proposition correct? Is it related to who proposed it? We have always accused some people of "ass determines their heads", but others are actually talking with their heads. Every time we stare at others' ass.
The common phenomenon in the blog Park is that if a person is talking about Microsoft technologies and other technologies, and "exactly" is talking about Microsoft, then "exactly" is the MVP. So good, there will certainly be many people who say that MVP is Microsoft's trust. I admit that some MVPs will be held by Microsoft for personal interests. For example, if you search for "mvp tfs" on Google, the first event is a glorious event. Ben Scheirman replied in a tfs mvp blog that "even if you have money, you will use free tools because they are more useful." The result is deleted. The other party writes a letter in private, saying that this is because he is making money using TFS consulting.
Does this mean that MVP is required? However, this is obviously the personal behavior of MVP, rather than the group practice of MVP. The reason is very simple, because Ben himself is also an MVP, so now it is "one MVP said that Microsoft products are not good, and its reply was deleted by another MVP ". So, do you mean that MVP is supported by Microsoft? Also, do you mean that I am from Microsoft?
In the same way, Oracle certified engineers say that Oracle is good, and Rails enthusiasts say that Rails is good. Do they all trust me? Do Open Source enthusiasts have open source support? I still think that excellent technical personnel must have faith and inclination. However, whether or not what they say is correct is not transferred based on their preference. the correctness of those things is objectively determined.
In my opinion, if the Community is to flourish, it is necessary to accept this kind of trend and try to maintain an objective mind. I often "think differently ". What we want is not harmony, but debate over objective things, rather than personal attacks. In my opinion, we have not done enough in this regard. We must continue to work hard.