PHP vs. ASP. NET (1)

Source: Internet
Author: User
Tags what is asp
You have many choices when talking about Web development. 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 should handle it. Similar to CGI, these codes run on the server and return some content, which is expressed as sending back to today's Web development, 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 should handle it. Similar to CGI, these codes run on the server and return some content, which shows the partial appearance of the HTML page returned to the browser. The open source scripting language PHP and Microsoft's ASP. NET Framework all belong to this type of language, and JavaServer Pages (JSP) and Perl/Mason also run in this way.

In this article, I will focus on the technologies that PHP-Oracle has chosen to merge into its products-and ASP. NET. I will outline the strengths and weaknesses of both, and focus on factors that will help you decide which technology your development project should choose. There are many factors to consider. different projects may resort to different technologies. In short, you will see a comparison of price, speed and efficiency, security, cross-platform support, and other aspects, as well as the advantages of open source code solutions.

What is ASP. NET?

ASP. NET, the latest version of ASP, is not completely backward compatible with earlier versions of ASP, because the software has been completely rewritten. In fact, the early ASP technology has much more in common with PHP than ASP. NET. ASP. NET is a complete framework used to build Web applications. One of the main features of this model is the flexibility of programming languages. ASP. NET can use scripting languages (such as VBScript, JScript, Perlscript, and Python) and compilation languages (such as VB, C #, C, Cobol, Smalltalk, and Lisp ). The new framework uses the universal language runtime environment (CLR). First, the source code of your language is compiled into Microsoft Intermediate language code, and then the CLR executes the code.

This framework also provides real object-oriented programming (OOP) and supports true inheritance, polymorphism, and encapsulation .. . NET class libraries are organized into inherited classes based on specific tasks (such as using XML or image processing.

In addition to programming languages and methods, database access is also a key concern. When you use ASP. NET programming, you can use ODBC to integrate the database. ODBC provides a set of consistent calling functions to access your target database.

Strengths and Weaknesses

The advantage of ASP. NET is its concise design and implementation. This is the dream of object-oriented programmers: flexible language and support for complex object-oriented features. In this sense, it can truly interwork with existing skills of programmers.

Another advantage of ASP. NET is its development environment. For example, developers can use WebMatrix (a tool supported by the community), Visual Studio. NET, or a variety of Borland tools (such as Delphi and C ++ Builder ). For example, Visual Studio allows you to set breakpoints, trace code segments, and view call stacks. All in all, it is a complex debugging environment. Many other third-party ASP. net ide solutions will also emerge.

However, if you get robustness, it will be at the cost of efficiency loss. ASP. NET consumes a lot of memory usage and execution time, most of which is due to a long code path. For Web-based applications, these limitations may be a serious problem, because on the Web, your applications may expand to thousands of users per second. Memory usage may also be a problem on the Web server.

What is PHP?

PHP is a script language based on the pre-processing HTML page model. When the PHP preprocessor in the Web server finds a PHP language mark like the following, it will call the PHP engine to execute the code:

Some code here
?>



Any programmer who has used imperative programming languages will be very familiar with PHP; you will find it syntactically similar to Perl, C, and Java. Strictly speaking, Java is a imperative programming language, but it also utilizes object-oriented structures and concepts. PHP draws on this structure when appropriate, but it is not a pure OOP language.

In the above discussion with ASP. NET, I mentioned the ODBC driver and how to build an application while considering database abstraction. In PHP, you can also use ODBC to talk to a database, so you already have a series of supported databases to choose from. There are also native drivers for MySQL, Oracle, and IPVs. In addition, if you want to use Oracle, a special OCI8 database will provide more access to Oracle, allowing you to use features such as LOB, BLOB, CLOB, and BFILE.

At this time, you may ask "why is the database-related database called the PHP feature ?" Database abstraction or independence is a factor to consider when you try to build an application that uses multiple databases or that needs to be transplanted between databases (for example, from development to production. These are indeed considerations.

However, as Tom Kyte pointed out in his new book, objective Oracle by Design (Oracle Press), database relevance will become your real goal, this maximizes your investment in this technology. If you perform general access to Oracle-whether using the ODBC or Perl DBI database, you will not be able to use the features that other databases do not have. In addition, the optimized query varies in different databases.

Zend Technologies is a commercial software company that has made significant contributions to PHP. It creates a commercial development environment called Zend Studio, which contains a complex debugger, a monitor, and other features. The company also built a free Zend Optimizer, which is used in combination with Zend Encoder to compile PHP code to improve performance. Other commercial products, such as Zend Performance Suite, can cache pre-compiled PHP pages to further significantly improve overall Performance.

Strengths and Weaknesses

PHP 5 still has some disadvantages until Beta 4, including the lack of exceptions and event-based error handling routines-they can interrupt normal program streams, 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, so programmers must use their own tools to determine how to handle errors, this will lead to lower consistency and often lead to re-engineering.

Another weakness is that PHP function names are case-insensitive. Although this is not a serious drawback, some programmers may find this feature very annoying.

However, I do have doubts about the object model of PHP. PHP is not specifically designed as an object-oriented language. Some of these features were added later-although you have noticed backward compatibility with PHP 3, the features of both models are retained. In fact, many of these vulnerabilities have been addressed in PHP 5. Pay attention to it.

If PHP lacks anything in some fields, it will quickly make up for what it is good. The price is reasonable, so you do not need to worry about licensing issues. It is also open-source, so the whole community will pay close attention to the development process: identify and fix errors. If you do not like a feature, you can modify the code. In addition, PHP can be combined with Apache: it can be compiled as a module or directly compiled into an Apache binary file.

However, running on Apache means that you can use PHP to invest on any server because Apache can run on Windows, Linux, Solaris, and other Unix platforms. In addition, using a web server with Apache tracking records means that security can be maintained at the highest priority. Finally, PHP has a smaller code path, which means less analysis and execution of PHP page server code, which will bring more efficient memory and usage and faster running.

What features are added in PHP 5?

PHP 5's 4th beta versions were launched by the end of December 2003. the change log clearly shows that many errors have been found and eliminated. Although it is still being tested, all its new features and advances are indeed worth noting.

The main new achievement of PHP 5 lies in its exception handling and a new object. the features introduced by this new object give PHP real OOP. Exception handling is undoubtedly one of the most significant shortcomings in PHP 4, and the introduction of PHP 5 to exception handling is undoubtedly a mature sign. Exception handling means that you have a language-defined and standardized error handling method in your software. By using try, catch, and throw methods, your PHP code becomes more robust and concise.


Class blue {

Function openFile ($ inFile ){
If (file_exists ($ inFile )){
# Code to open the file here
} Else {
Throw new Exception
("Cannot open file: $ inFile ");
}
}
}

$ BlueObj = new blue ();

Try {
$ BlueObj-> openFile ('/home/shull/file.txt ');

} Catch (Exception $ myException ){
Echo $ myException-> getMessage ();

# Rest of exception handling code here
}

# Rest of blue methods here

?>



The new object model has a lot of positive impact on PHP programs. In PHP 4, when an object is passed to a function or method, the value is passed-unless you explicitly inform PHP. This process means that one copy of the object (all data structures in the memory) must be copied ). This step uses memory to make access slow and congested. In PHP 5, objects are usually passed through references.

The new object-oriented features (including constructors and Destructor) in PHP 5 are worth noting. Similar to C ++ and Java, they provide a standard method, that is, using a constructor method to create objects, allocate memory, and execute any necessary settings, A destructor is used to clean up the data.

PHP 5 also introduces more refined control over Chinese methods and variables. In PHP 4, everything is public: you can access variables in your class from outside the class or in the inherited class. 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 in the class itself. You can also protect them, that is, you can view methods and variables in the class or in the subclass.

In addition, PHP 5 introduces type prompts or better type checks. When you pass an object to a routine, PHP can check whether it is of the correct type and generate a type mismatch error when the check fails.

Because there are other features (such as static methods, variables, and abstract classes), be sure to view the document for details.

(To be continued)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.