A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
PHP, which has just made a historic breakthrough in the programming language ranking in September, is probably the most powerful opponent in the Web development field, namely ASP. NET based on Microsoft. NET technology. Recently, Microsoft's Joe Stagner published a series of articles on the performance of PHP and ASP. NET, which caused a lot of responses from programmers on both sides. Joe said he would continue this test and look for a more appropriate way to draw conclusions that are as valuable as possible for the actual project.
Joe said in his blog that in general, the purpose of performance testing is to try to prove that one party is faster than the other party. I am employed by Microsoft and write PHP and ASP. NET code at the same time. I used PHP before. NET. I like it very much.
Therefore, it is difficult for me to tell which one is better. When I talk about PHP, my Microsoft colleagues will write a letter to criticize me. when I post comments that tend to be ASP. NET, My PHP friends will say that I am the trust of Microsoft.
I did this test because everyone has their own opinions on PHP performance (Windows vs. Linux & 5.2 vs. 5.3), but no one can give clear data.
The test environment for ASP. net php is as follows:
All tests run on the same machine (with 4 GB memory and 60 GB 7200 RPM hard drive Toshiba Tecra M5 ).
Ubuntu 9 and Windows Server 2008 Standard Edition are installed on independent (but identical) hard disks.
Linux uses Apache2 and Windows uses IIS 7 as their respective Web servers.
The operating systems of both parties have completed patches or upgrades.
Both systems and runtime are not performing any extra performance enhancement.
From the experiment results, PHP has different performance in Linux and Windows:
Pure statement execution is better on Windows.
Function calls are faster on Windows.
Object creation and access are faster for PHP 5.2 in Linux, but faster for PHP 5.3 in Windows.
Class library calls are much faster on Linux (for example, encryption on Ubuntu is 3 to 5 times faster than that on Windows ).
Comparison between Linux and Windows platforms
The file access performance in Linux is slightly higher than that in Windows, but the file replication performance in Windows is 60% slower than that in Linux, probably because of the advanced ACL security.
Accessing MySQL on Linux is much faster than that on Windows, and running PHP 5.3 on Windows is worse (but from the perspective of PostgreSQL below, this should be due to poor implementation ).
PostgreSQL's performance on the two platforms is very close (the gap between 1000 operations is less than 0.06 seconds)-whether it is PHP 5.3 or PHP 5.2, Windows performance is slightly better.
On Windows, the performance of PHP 5.2 to access ms SQL Server is slightly inferior to that of MySQL on Linux (at this time, SQL Server for PHP 5.3 is not supported ).
For pure PHP execution performance, Linux and Windows are almost the same, which will not be the decisive factor for choosing Linux or Windows as the deployment platform. If you are building an application, PostgreSQL may be a better choice. Because it performs well on both platforms.
If your application must use MySQL, you need to plan the scalability before selecting Windows (I personally think Sun is unlikely to optimize MySQL Performance for Windows ).
The SQL Server driver in the first PHP version is slower than MySQL or PostpreSQL, but this should not be a problem. The drive of the second version is under development, which will improve the performance.
In Joe's view, the PHP and IIS teams have been doing very well in terms of execution performance. Next, we need teams of open-source programs (Drupal, WordPress, Joomla, etc) optimized the performance of each platform.
However, in addition to file replication, ASP. NET outperforms PHP in terms of performance (whether deployed on Linux or Windows ):
Access to MySQL on Linux is slightly better than access to SQL Server on Windows (using common data types and SELECT statements ). However, the gap is almost negligible.
ASP. NET (C #) operations, such as object usage and class library calls, have far higher performance than PHP. For this test result, Joe added:
I know some of my PHP friends and Linux guys are about to jump out and refute my tests and results.
I have been thinking about whether to add some advanced optimization options for such performance comparison. However,. NET also supports multithreading, asynchronous requests, and various caching methods.
Please note -- I didn't say "ASP. NET is faster, so you shouldn't use PHP !", In my opinion, PHP is too simple to make it difficult for some advanced applications, just like ASP. NET will have learning complexity in the early stage of the project.
For me, the most exciting thing about PHP is not its language/platform, but thousands of smart PHP developers, and a variety of excellent projects (such as Drupal, Joomla, WordPress, PHPBB, Nuke, etc ).
So we can think that the performance of PHP on Windows and Linux is at the same level. now I can write PHP class libraries for Windows that I hope for many years.
Joe also published the test code. He said that if you have doubts about the test results, you can perform the experiment yourself or write your own test code for testing.
After the article was published, many netizens expressed their views on the test results. Joe basically replied to the main points one by one:
"I only use ASP. NET because I like Visual Studio IDE" -- I personally think Visual Studio is the most productive development tool. However, PHP has a good choice. I use Zend Studio, PHPEd, Komodo, Delphi for PHP, and these are all very good. I hate Eclipse, but Zend also makes a lot of extensions for PHP development.
Compare ASP performance-no, thanks. There is a big gap between the old ASP and the current PHP and ASP. NET. It seems that ASP is recommended to be used to develop a new project. I strongly recommend that you do not do this.
Comparison between 32-bit and 64-bit systems
Comparison between 32-bit and 64-bit systems-these tests are not designed to reflect performance gaps in 64-bit systems. In future tests, I will add 64-bit scenarios.
"PHP is ugly"-oh, I don't agree. Old ASP is much more ugly. You can write terrible and ugly PHP code, and write ugly and terrible C # or VB code. Similarly, you can write an elegant C ++ style PHP. This is only related to developers' skills.
Apache on Windows should be used for testing-Apache is a Linux server, but I think that if you do not use IIS 7 on Windows, too much will be lost.
"Is there a way to speed up file copy performance without compromising security in Win2K8 ?" -- It does not seem to work. I think this involves the ACL system on the Windows Server. In the future, I may test the performance of reading files through data streams, and the performance of some things may be improved. However, Web applications generally do not Program to copy a large number of files.
"PHP has always been, and it will always be a semi-professional environment. On the PHP platform, there are many professional, high-quality applications, and many highly respected developers. Whether it is professional is a problem for developers, not PHP or ASP. NET.
"I think PHP without opcode cache is unfair ,. NET is compiled and executed, and PHP needs to explain and 'compile 'the page each time. I agree that this test may not be complete, but I do not agree with this logic. The method for testing PHP is the same as that for downloading and installing PHP. No op-code cache is installed on my VM. In fact, adding this feature to ASP. NET does not mean testing is unfair because PHP lacks this feature-but this requirement is reasonable and I am preparing a new test.
"It is unreasonable to say that PHP is not a 'professional 'language, because almost all of the largest websites are built using PHP."-this is not true, however, it is also wrong to say that those sites are "almost all" built with PHP. Some are, some are not.
If you see this data, I am naturally very happy to have more confidence in ASP. NET. If I don't think. NET is a better choice for developing Web applications-at least not on other platforms, then I won't work at Microsoft.
But ...... If you ignore PHP because of this data, it is also a wrong and naive behavior.
From a purely technical perspective, I think. NET is far more powerful than PHP, but this does not mean PHP is not powerful enough. In my opinion, the power of PHP is embodied in a large number of applications and available frameworks.
About a week later, Joe published the results of the second Test. Compared with the previous test, the second Test has the following two major changes:
The op-code cache is installed for Linux and Windows, and most tests are re-run.
Due to some dependency problems, the testing platform of PHP 5.3 + APC has become the Debain 5 operating system.
For the second Test and its results, Joe explains:
From the results, the performance gap between running PHP on Ubuntu and Debian is negligible. The performance of some items is slightly improved, while that of some items is 25%, but the overall performance is lower than I imagined.
After APC is used, the running of some items slows down, but I think this is only the error caused by the machine. Note that not the first result shown in the table is refreshed twice, and the result is obtained when the cache hits.
I think the current test is very fair.
Empty loop tests and empty function execution are very important because they reflect the basic consumption of languages or platforms. This is an important consideration for performance consumption outside of performance overhead such as page transmission.
Some of my PHP friends also agree on the accuracy of this test, but I am very insightful to add:
In addition, according to the results of the previous experiment, when running PHP on the Windows platform, there were some performance problems with MySQL and file access. many Microsoft Teams obtained relevant information from me. We hope this data can be converted into practical improvements.
Joe said he will collect test scenarios that everyone thinks are more fair and meaningful. The following are the testing projects he planned:
Actual page test: cyclic, cold/hot calls, and object operations are a type of test, but the overall presentation of the page is another meaningful test.
Load testing: Which environment can process more requests at the same time.
In the load test, the performance of which side will decrease faster.
What is the performance of the 64-bit platform in various situations.
PHP performance tests on Linux and Windows platforms have also been conducted in China. At the WordCamp China 2009 conference, Microsoft announced the performance evaluation results of its cooperation with Kang shengchuangxiang: running PHP on Windows Server 2008 + IIS, from the average time, the number of requests processed per second and the data throughput are much more convenient than the Linux + Apache hosting method.
Which of the following is better for asp.net and php?
Asp.net is something of Microsoft. its development prospects depend on Microsoft's attitude.
Before. net, Microsoft implemented ASP. With the strong promotion of Microsoft, it still looks promising. But now, Microsoft wants to promote asp.net, and ASP has become an obstacle. Since Windows Server 2003, Microsoft has made many restrictions on ASP, such as uploading files cannot exceed KB. Now let's take a look at what Microsoft has done to promote Windows Vista and the latest Windows 7, Windows XP, and stop the technical support for common users, to force you to change the OS.
If Microsoft has something better than. net in the future. Microsoft estimates that it will impose similar restrictions on. net to force users to upgrade.
PHP is completely open-source, and its needs are closer to the daily applications. the code style is similar to the C language, which is easier to learn.
In terms of speed, although PHP is not compiled, the execution efficiency of practical applications in Linux must be faster than that in Windows. net.
The runtime security PHP must be higher than Microsoft's. net. However, the code is usually unprotected. It usually needs to be encrypted using commercial Zend software. Of course, this encryption process is also a compilation process. While protecting the code, it also improves the execution speed. The new Zend encryption algorithm has not been successfully cracked yet. However, if. net only supports simple compilation, it will be easily decompiled back.
PHP currently has two branch lines: PHP4 and PHP5. Both branches are under common maintenance. This ensures that the system using PHP4 in the past can still ensure continuous and sound security and function updates.
Which of the following is more promising for ASP. NET and PHP?
ASP full name Active Server Pages is a WEB Server development environment that can be used to generate and run dynamic, interactive, and high-performance WEB service applications. ASP uses the script language VBScript (Java script) as its own development language.
PHP is a cross-platform server-side embedded scripting language. It relies heavily on the syntax of C, Java, and Perl, coupled with PHP's own features, so that WEB developers can quickly write dynamic pages. It supports the vast majority of databases currently. Another point is that PHP is completely free of charge. you can freely download it from the official site of PHP (http: // www.php.net. In addition, you can obtain the source code without restrictions, and even add the features you need.
JSP is a new generation of site development language released by Sun. it completely solves a common problem of ASP and PHP-script-level execution (it is said that PHP4 is also supported by Zend, compile and run ). With its extraordinary accomplishments in Java, Sun has made a new achievement in Java applications and Java applets, namely JSP-Java Server Page. Jsp supports powerful site programs with the support of Serverlet and JavaBean.
All three provide the ability to mix some program code in HTML code and explain and execute the program code by the language engine. However, JSP code is compiled into a Servlet and interpreted and executed by the Java virtual machine. This compilation operation only occurs during the first request to the JSP page. In ASP, PHP, and JSP environments, HTML code describes the display style of information, while program code describes the processing logic. Common HTML pages only depend on Web servers, while ASP, PHP, and JSP pages require additional language engines to analyze and execute program code. The execution result of the program code is re-embedded into the HTML code and sent to the browser together. ASP, PHP, and JSP are all Web server-oriented technologies. client browsers do not require any additional software support.
You can use VBScript, JScript, and other easy-to-understand scripting languages and HTML code to quickly complete website applications.
Compile compilation is not required, which is easy to compile and can be directly executed on the server.
Use a common text editor, such as a Windows Notepad, to edit the design.
Browser Independence. the user can view the webpage content designed by Active Server Pages by using a Browser that can execute HTML code. The scripting languages (VBScript and Jscript) used by Active ServerPages are all executed on the WEB server. the user-side browsers do not need to be able to execute these scripting languages.
Active Server Pages are compatible with any ActiveX scripting language. In addition to using VB Script or JScript, you can also use other scripting languages provided by a third party, such as REXX, Perl, and Tcl, in plug-in mode. The script engine is a COM (Component Object Model) Object that processes the script program.
You can use the server scripts to generate client scripts.
ActiveX Server Components (ActiveX Server component) is infinitely scalable.
You can use Visual Basic, Java, Visual C ++, COBOL, and other programming languages to compile your required ActiveX Server Component.
PHP can be compiled into functions connected to many databases. PHP and MySQL are a perfect combination. You can also write peripheral functions to indirectly access the database. In this way, when you change the database you are using, you can easily change the encoding to adapt to this change. PHPLIB is the most commonly used base database to provide general transactions. However, the database interfaces provided by PHP are different from each other. for example, the interfaces for Oracle, MySQL, and Sybase are different from each other. This is also a weakness of PHP.
PHP provides classes and objects. Web-based programming requires object-oriented programming capabilities. PHP supports constructors and extraction classes.
Separate content generation and display
With JSP technology, Web page developers can use HTML or XML tags to design and format the final page. Use JSP identifiers or small scripts to generate dynamic content on the page. The logic of the generated content is encapsulated in the identifiers and JavaBeans components and bundled in small scripts. all scripts run on the server. If the core logic is encapsulated in identifiers and Beans, other people, such as Web administrators and page designers, can edit and use JSP pages without affecting content generation.
On the server side, the JSP Engine interprets JSP identifiers and small scripts to generate the requested content (for example, accessing the JavaBeans component, using the JDBCTM technology to access the database, or including files ), in addition, the results are sent back to the browser in the form of HTML (or XML) pages. This helps the author protect his own code and ensure the full availability of any HTML-based Web browser.
Most JSP pages depend on reusable cross-platform components (JavaBeans or Enterprise JavaBeans components) to perform more complex processing required by applications. Developers can share and exchange components that perform common operations, or make these components used by more users or customer groups. The component-based approach accelerates the overall development process and balances various organizations in their development efforts with their existing skills and optimization results.
Simplified page development with logo
Web page developers are not all programmers familiar with the scripting language. The assumerver Page technology encapsulates many functions that are required for dynamic content generation in easy-to-use and JSP-related XML identifiers. The standard JSP mark can access and instantiate the JavaBeans component, set or retrieve component attributes, download the Applet, and execute functions that are more difficult to encode and consume in other ways.
Through the development of a custom identification library, JSP technology can be expanded. In the future, third-party developers and others can create their own identification libraries for common functions. This allows Web page developers to work with familiar tools and components that execute specific functions like identifiers.
JSP technology can easily be integrated into a variety of application architectures to take advantage of existing tools and techniques and extend to support enterprise-level distributed applications. As part of the Java technology family and an integral part of Java 2 (Enterprise Edition architecture), JSP technology can support highly complex Web-based applications.
Because the built-in scripting language of JSP pages is based on the Java programming language, and all JSP pages are compiled into Java servlets, JSP pages have all the advantages of Java technology, including robust storage management and security.
As part of the Java Platform, JSP features the Java programming language "one-time writing, running everywhere. As more and more vendors add JSP support to their products, you can use the servers and tools you select. changing tools or servers does not affect the current application.
ASP is a dynamic web page language developed by Microsoft and inherits the consistent tradition of Microsoft products-it can only run on Microsoft's Server products, IIS (Internet Information Server) (windows NT) and PWS (Personal Web Server) (windows 98. There are also ChiliSoft plug-ins in Unix to support ASP. However, ASP has limited functions and must be expanded through the combination of ASP + COM. it is very difficult to implement COM in Unix.
PHP3 can run normally on Windows, Unix, and Linux Web servers. It also supports common Web servers such as IIS and Apache. you do not need to change the PHP3 code when changing the platform, ready for use.
JSP is similar to PHP3 and can run on almost all platforms. For example, in Windows NT, Linux, and Unix. NT, IIS supports JSP through a plug-in, such as JRUN or ServletExec. The famous Web server Apache already supports JSP. Because Apache is widely used in NT, Unix, and Linux, JSP has a wider operating platform. Although the NT operating system has a large market share, the Unix advantage in the server is still great, and the new Linux is not small. Porting from one platform to another, JSP and JavaBean do not even need to be re-compiled, because Java bytecode is standard and platform-independent.
Some people have performed tests to test the cyclic performance of these three languages and to access the Oracle database.
In the cyclic performance test, JSP ended the 20000*20000 loop in just four surprising seconds. ASP and PHP test 2000*2000 cycles (one order of magnitude less), but they use 63 s and 84 s respectively. (Refer to PHPLIB ).
In the database test, the three performed 1000 Insert, Update, Select, and Delete operations on Oracle 8 respectively. it took 13 seconds for JSP, 69 seconds for PHP, and 73 seconds for ASP. Foreground analysis is currently the most widely used in PHP and ASP in China. JSP is a relatively new technology, which is rarely used in China. However, in foreign countries, JSP is already a popular technology, especially for e-commerce websites, mostly using JSP.
Websites using PHP, such as sina and Chinaren, are not suitable for large-scale e-commerce sites due to some shortcomings of PHP, it is more suitable for some small commercial sites.
First, PHP lacks support for scale. Second, the lack of multi-layer structure support. For heavy-load sites, there is only one solution: distributed computing. The database and application logic layers are separated from each other, and the same layer can also be separated by traffic to form a two-dimensional array. PHP lacks such support. As mentioned above, the database interfaces supported by PHP are not uniform, which makes it unsuitable for e-commerce.
ASP and JSP have no such defects. ASP can obtain ActiveX scale support through Microsoft Windowsd COM/DCOM, and obtain structure support through DCOM and Transcation Server; JSP can be scaled through SUN Java's Java Class and EJB, and structural support can be obtained through EJB/CORBA and Application Server of many vendors.
Among the three, JSP should be the future development trend. Some big e-commerce solution providers in the world use JSP/Servlet. Ibm e-business is a well-known company. its core is to use JSP/Servlet Web Sphere. another famous Western E-commerce software provider, Intershop, its original products Intershop1, 2, 3, and 4 occupy the main share of e-commerce software.
To sum up, jsp should be more promising!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service