Home  >  Article  >  Backend Development  >  PHP and ASP.NET head-to-head confrontation 1_PHP tutorial

PHP and ASP.NET head-to-head confrontation 1_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:27:02934browse

When it comes to web development these days, you have many options. Many of these methods involve preprocessing—that is, embedding code into HTML pages using specific tags that tell the preprocessor that they contain code and that it should be processed. Much like CGI, these codes run on the server and return some content that appears as part of the resulting HTML page that is sent back to the browser. The open source scripting language PHP and the languages ​​in Microsoft's ASP.NET framework fall into this category; JavaServer Pages (JSP) and Perl/Mason also operate this way. In this article, I'll focus on PHP—the technology Oracle has chosen to incorporate into its products—and ASP.NET. I will outline the various strengths and weaknesses of both and focus on those factors that will help you decide which technology you should choose for your development project. There are many factors to consider, and different projects may resort to different techniques. In summary, you'll see a side-by-side comparison on price, speed and efficiency, security, cross-platform support, and more, as well as the benefits of open source solutions. What is ASP.NET? The latest version of ASP, ASP.NET, is not fully backwards compatible with earlier versions of ASP because the software was completely rewritten. Early ASP technology actually had much more in common with PHP than with ASP.NET, a complete framework for building Web applications. One of the main features of this model is the flexibility in choosing a programming language. ASP.NET can use scripting languages ​​such as VBScript, JScript, Perlscript, and Python as well as compiled languages ​​such as VB, C#, C, Cobol, Smalltalk, and Lisp. The new framework uses the Common Language Runtime (CLR); your language's source code is compiled into Microsoft intermediate language code, which is then executed by the CLR. This framework also provides true object-oriented programming (OOP) and supports true inheritance, polymorphism, and encapsulation. .NET class libraries are organized into inheritable classes based on specific tasks (for example, working with XML or image processing). In addition to programming languages ​​and methods, database access is also a factor to focus on. When you program in ASP.NET, you can use ODBC to integrate your database; ODBC provides a consistent set of function calls to access your target database. Strengths and Weaknesses The strength of ASP.NET is clearly its simplicity of design and implementation. It's an object-oriented programmer's dream: the language is flexible and supports complex object-oriented features. In this sense, it is truly interoperable with programmers' existing skills. Another advantage of ASP.NET is its development environment. For example, developers can use WebMatrix (a community-supported tool), Visual Studio .NET, or various Borland tools such as Delphi and C++ Builder. For example, Visual Studio allows setting breakpoints, tracing code snippets, and viewing call stacks. All in all, it's a complex debugging environment. Many other third-party ASP.NET IDE solutions are bound to appear. But what you gain in robustness comes at the cost of efficiency. ASP.NET is very expensive in terms of memory usage and execution time, mostly due to longer code paths. For Web-based applications, these limitations can be a serious problem, because on the Web, your application may scale to thousands of users per second. Memory usage can also become an issue on the web server. What is PHP? PHP is a scripting language based on the preprocessed HTML page model. When the PHP preprocessor in the web server finds a PHP language tag like the following, it calls the PHP engine to execute the code: PHP will be very familiar to any programmer who has used an imperative programming language; you will find It has syntactic similarities with Perl, C, and Java. Strictly speaking, Java is an imperative programming language, but it also makes use of object-oriented structures and concepts. PHP borrows from this structure where appropriate, but it is not a pure OOP language. In the above discussion of ASP.NET, I mentioned the ODBC driver and how applications are built with database abstraction in mind. In PHP you can also use ODBC to talk to a database, so you already have a range of supported databases to choose from. There are also native drivers for MySQL, Oracle and Postgres. Additionally, if you want to use Oracle, there is a special OCI8 library that will provide more access to Oracle, allowing you to use features such as LOBs, BLOBs, CLOBs, and BFILEs. At this point you might be asking "Why are database-related libraries called a feature of PHP?" Database abstraction or independence is an important aspect when you are trying to build a system that uses multiple databases or need to be portable between databases (e.g., from development to production). a factor to consider when porting) applications. And these are indeed things that should be cared about and considered. But as Tom Kyte points out in his new book — Effective Oracle by Design (Oracle Press) — database dependency becomes your real goal because it maximizes your investment in the technology. If you have general access to Oracle—either through ODBC or Perl's DBI library—then you won't be able to use features that other databases don't have.Additionally, optimized queries vary across databases. Zend Technologies is a business software company that has made significant contributions to PHP. It created a commercial development environment called Zend Studio that included a sophisticated debugger, a monitor, and other features. The company also built the free Zend Optimizer, which works in conjunction with Zend Encoder to compile PHP code for improved performance. There are other commercial products, such as Zend Performance Suite, which can cache precompiled PHP pages, further improving overall performance significantly. Strengths and Weaknesses As of Beta 4, PHP 5 still has some shortcomings, including the lack of exception and event-based error handling routines - their ability to interrupt the normal program flow and jump the code to a special error handling section. Java also provides exceptions for error handling, while C++ provides exception handling through try, catch and throw syntax. Of course, you can still manage errors in PHP, but the structure is not standardized, leaving programmers with their own tools to decide how to perform error handling, which leads to less consistency and often a need to start over. Another weakness is that PHP function names are not case-sensitive. Although this is not a serious disadvantage, some programmers may find this feature annoying. However, I do have concerns about PHP's object model. PHP is not specifically designed as an object-oriented language. Some of these features were added later — although care was taken to maintain backward compatibility with PHP 3, so some features from both models remain. In fact, many of these weaknesses have been addressed in PHP 5. Please pay attention. What PHP lacks in some areas, it quickly makes up for in areas where it excels. The price is reasonable so you don't need to worry about licensing issues. It's also open source, so the entire community will follow the development process closely: bugs will be found and fixed. If there's a feature you don't like, you can modify the code. Additionally, PHP integrates naturally with Apache: it can be compiled as a module, or directly into Apache binaries. But running on Apache means that, with PHP, you can leverage the investment you've made in any server, because Apache runs on Windows, Linux, Solaris, and various other Unix platforms. Additionally, using a web server with a track record of Apache means security can be kept at the highest priority. Finally, PHP has a smaller code path, which means less server-side code to parse and execute PHP pages, which results in more efficient memory and usage and faster execution. What are the new features in PHP 5? The 4th beta version of PHP 5 was launched at the end of December 2003, and the change log clearly shows that many bugs were found and eliminated. While it's still in testing, all of its new features and advancements are certainly worth keeping an eye on. The main new achievements of PHP 5 are its exception handling and a new object that introduces features that give PHP true OOP. Exception handling is undoubtedly one of the most significant shortcomings in PHP 4, and the introduction of exception handling in PHP 5 is undoubtedly a sign of maturity. Exception handling means that you have language-defined and standardized error handling methods in your software. Just use try, catch and throw methods and your PHP code becomes more robust and concise. openFile (/home/shull/file.txt); } catch (Exception $myException) { echo $myException->getMessage (); # rest of exception handling code here } # rest of blue methods here ?> new The object model brings many positive effects to programs written in PHP. In PHP 4, when you pass an object to a function or method, it is passed by value — unless you explicitly tell PHP otherwise. This process means that a copy of the object (all data structures in memory) must be made. This step uses memory, making access slow and congested. In PHP 5, objects are usually passed by reference. The new object-oriented features in PHP 5, including constructors and destructors, are worth paying attention to. Like C++ and Java, they provide a standard way to create an object, allocate memory, and perform any necessary setup through a constructor method, and perform cleanup through a destructor method. PHP 5 also introduces finer control over methods and variables within classes. In PHP 4, everything is public: you can access variables in your class from outside the class or in inherited classes. In PHP 5, you can still make variables or methods public, but you can also make them private so that they can only be used within the class itself. They can also be protected, that is, methods and variables can be viewed within the class or in subclasses. Additionally, PHP 5 introduces type hints or better type checking. When you pass an object to a routine, PHP is able to check that it is the correct type and generate a type mismatch error if the check fails.Since there are other features such as static methods and variables and abstract classes, be sure to check the documentation for details. (To be continued)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531910.htmlTechArticleWhen it comes to web development these days, you have many options. Many of these methods involve preprocessing — that is, embedding code into the HTML page using specific tags that tell the preprocessor to...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn