Tuesday, November 9, 2010

Migrating from PHP to ASP.NET- part1

Source: Microsoft Corporation


September 2003

Applies to:

Microsoft® ASP.NET

Microsoft Visual Basic® .NET

Contents

Introduction

Architecture Comparison

Feature Comparison

Comparing Syntax and Common Tasks

Data Caching and Page Caching

Summary

Recommended Next Steps

Resources

Introduction

This paper discusses the migration of PHP (PHP:Hypertext Preprocessor 4) to ASP.NET. It compares and contrasts the basic underlying syntax of PHP with Microsoft® Visual Basic® .NET, as well as the underlying functionality and architecture of the two systems.

While both PHP and ASP.NET allow you to build sophisticated and complex Web applications (like e-commerce sites, intranets, and corporate portals), PHP and ASP.NET have several major differences. Unlike PHP, ASP.NET is not a language or a parser but rather a set of technologies in the Microsoft .NET Framework for building Web applications and XML Web Services. Microsoft ASP.NET pages execute on the server like PHP and generate markup, such as HTML, WML or XML, which is sent to a desktop or to mobile applications. ASP.NET, though, is different in that it provides a robust, object-oriented, event-driven programming model for developing Web pages, while still maintaining the simplicity that PHP developers are accustomed to.

ASP.NET applications are based on a robust Object Oriented Programming (OOP) paradigm rather than a scripting paradigm. This allows for more rigorous OOP features, such as inheritance, encapsulation and reflection. While most basic and simple operations can easily be translated from PHP to ASP.NET, more complex applications will not be as simple to convert from PHP to ASP.NET and will require careful planning and consideration as well as a more OOP approach.

In this paper, we assume that the reader has experience with PHP as well as programming and software development in general. We begin this paper with a look at code with a short comparison of the underlying architectural differences and the OOP development model, followed by a feature comparison, and then a comparison of Syntax and Common tasks for developing Web applications with PHP and ASP.NET.

Note If you would like to skip the migration details, and simply test drive ASP.NET, feel free to jump to the Recommended Next Steps section.

Architecture Comparison

As you will learn from the syntax and language comparison and the end of this paper, PHP and ASP.NET are relatively similar with analogous functionality and syntax. PHP, however, is very different from ASP.NET at a lower architectural level. PHP is based on a platform-independent processor/engine that parses PHP scripts and provides for database connections, Internet protocol compliance, and numerous other tasks common to most Web application platforms.

ASP.NET is a framework built upon a series of technologies such as the CLR and offers an extensive series of well-organized class libraries that provide for most every conceivable set of functionality that would be used in a Web application. It also allows for the easy and simple creation of components to extend the framework.

While PHP offers similar things, such as the PEAR libraries, PHP and ASP.NET are not truly analogous because the ASP.NET framework is built from the ground up on an OOP paradigm and OOP concepts; PHP is not. This difference is most apparent in the ways you access classes and objects in PHP and ASP.NET.

Object-Oriented Programming in PHP and ASP.NET

Both PHP and ASP.NET offer OOP paradigms to application development, but their support for various OOP concepts, such as encapsulation and polymorphism differ. For example, PHP only supports partial encapsulation (such as support for declaring methods and fields in the class) and partial polymorphism (no overloading, no abstraction). PHP also lacks support for such concepts and accessibility in that there is no concept of private, public, or protected functions in classes as well as the Overloading. While OOP purists may debate that ASP.NET and the various languages do not fully support every concept in the OOP paradigm, this is true of most languages considered OOP, such as C++ and Java.

This has both an upside and a downside. The downside is that for some Web developers there is a steeper learning curve for ASP.NET versus PHP, which offers a scripting paradigm that developers have traditionally employed for building Web sites. However, developers who have a background in OOP languages and/or Vwill find ASP.NET intuitively familiar and easy to learn.

The upside to ASP.NET's support of OOP concepts means that ASP.NET applications for the most part result in better designed code, have clear separation of content, logic, and data and thus are generally easier to support over the long term of a applications life cycle. In addition, ASP.NET's native support for enterprise technologies such as Message Queuing, Transactions (see the .NET Framework's System.EnterpriseServices classes) SNMP, and Web Services, makes it simple to develop highly scalable and robust applications.

You can find an introduction to the main areas of object-oriented programming (from a Visual Basic point of view) in Object-Oriented Programming in Visual Basic.

Compilation

PHP

When a PHP page is requested, the HTML and inline PHP script is compiled to Zend Opcodes. Opcodes are low-level binary instructions that will be used to serve the PHP page. After compilation, the Zend Engine runs the opcodes (similar to the way Java's runtime engine runs byte code), and then HTML is generated and served to the client.

There are a number of commercial products that can be used to speed up the execution of a PHP page by optimizing these opcodes. Other ways to increase performance of PHP scripts include caching the opcode and caching the generated HTML.

ASP.NET

When a request is made to IIS (Internet Information Services) or another Web server for an .aspx page (or any other extension supported by ASP.NET), the request is passed to ASP.NET for processing. If this is the first time the page has been requested, ASP.NET compiles the page to MSIL (Microsoft intermediate language). This MSIL code is then processed by the CLR (common language runtime) to machine code. Then the request is run using this compiled code. Subsequent requests are served from this same machine code assuming the page has not been modified.

It is important to note that the binary code that is generated by the CLR is already as optimized as possible; no add-on product is necessary to achieve maximum performance.

It is also important to note that everything in ASP.NET is compiled to machine code before being run. Even HTML text is converted to a string literal control and inserted in proper order into the control tree.

No comments:

Post a Comment