PHP asp.net comparison [recommended]_ related tips

Source: Internet
Author: User
Tags error handling exception handling gettext object model oracleconnection php and php code zend
These tags tell the preprocessor that they contain code and should handle them. Very similar to CGI, the code runs on the server and returns some content that appears as part of the appearance of the resulting HTML page sent back to the browser. Open source scripting language all languages in PHP and Microsoft's asp.net framework are of this type; JavaServer Pages (JSP) and Perl/mason are also running in this way.
In this article, I will focus on the technologies php-oracle have chosen to incorporate into their products-and asp.net. I will outline the strengths and weaknesses of both, and focus on the factors that will help you decide which technology your development project should choose. There are a number of factors to consider, and different projects may have recourse to different technologies. In summary, you'll see a comparison of price, speed and efficiency, security, cross-platform support, and the advantages of open source solutions.
What is asp.net?
ASP's latest version of ASP.net is not entirely compatible with earlier versions of ASP, because the software is completely rewritten. Early ASP technology actually has more in common with PHP than with ASP.net, asp.net is a complete framework for building WEB applications. One of the main features of this model is the flexibility to choose a programming language. asp.net can use scripting languages (such as VBScript, JScript, PerlScript, and Python) and compiled languages (such as VB, C #, C, Cobol, Smalltalk, and Lisp). The new framework uses the common language runtime Environment (CLR), the source code for your language is compiled into the Microsoft intermediate language code, and then the CLR executes it.
The framework also provides true object-oriented programming (OOP) and supports true inheritance, polymorphism, and encapsulation. The. NET class libraries are organized into inheritable classes based on specific tasks, such as using XML or image processing.
In addition to programming languages and methods, database access is a key concern. When you are programming with asp.net, you can use ODBC to integrate your database; ODBC provides a consistent set of call functions to access your target database.
Strengths and weaknesses
ASP.net's advantage is obvious in its simplicity of design and implementation. This is the dream of object-oriented programmers: language flexibility, and support for complex object-oriented features. In this sense, it really can interoperate with the skills that programmers already have.
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 you to set breakpoints, track code snippets, and view call stacks. In short, it is a complex debugging environment. Many other third party asp.net IDE solutions will also be inevitable.

But if you are robust, you will be at the expense of loss efficiency. ASP.net is very expensive in terms of memory usage and execution time, mostly due to longer code paths. These limitations can be a serious problem for web-based applications, because on the Web, your application can expand to tens of thousands of users per second. Memory usage can also become a problem 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 discovers a PHP language tag like the following, the PHP engine is invoked to execute the code:
<?php
Some code here
?>
Any programmer who has used an imperative programming language will be familiar with PHP, and you will find that it is syntactically similar to Perl, C, and Java. Strictly speaking, Java is an imperative programming language, but it also leverages object-oriented structures and concepts. PHP draws on this structure when it is appropriate, but it is not a purely OOP language.
In the above discussion of ASP.net, I mentioned the ODBC driver and how to build the application when considering database abstraction. In PHP, you can also use ODBC to talk to a database, so you already have a list of supported databases to choose from. There are also MySQL, Oracle and Postgres native drivers. In addition, if Oracle is to be used, a special OCI8 library will provide more access to Oracle, allowing you to use features such as LOB, BLOB, CLOB, and BFILE.
You might ask, "Why is database-related repositories called PHP features?" "Database abstraction or independence is one factor to consider when trying to build an application that uses multiple databases or needs to migrate between databases (for example, porting from development to production)." And these are really things that should be cared for and considered.
But as Tom Kyte points out in his new book-Effective Oracle by (Oracle publishing House)-database dependencies will be your real goal, as this will maximize your investment in the technology. If you have general access to Oracle-whether through ODBC or Perl DBI libraries-you will not be able to use features that are not available in other databases. In addition, the optimized query is different in each database.
Zend Technologies is a commercial software company that has made a significant contribution to PHP. It creates a commercial development environment called Zend Studio, which includes a complex debugger, a profiler, and other features. The company also builds free Zend Optimizer, which is used in conjunction with Zend Encoder to compile PHP code to improve performance. There are other commercial products, such as the Zend performance Suite, which can cache precompiled PHP pages to further significantly improve overall performance.

Strengths and weaknesses
To Beta 4, PHP 5 still has some drawbacks, including missing exceptions and event-based error-handling routines-they can disrupt normal program flow and jump 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 that programmers have to use their own tools to determine how to perform error handling, which leads to lower consistency and often leads to rework.
Another weakness is that PHP's function names are case-insensitive. While this is not a serious shortcoming, some programmers may find this feature annoying.
However, I do have doubts about the PHP object model. PHP is not designed specifically as an object-oriented language. Some of these features were added later-despite the attention to maintaining a back-end compatibility with PHP 3, the characteristics of both models remain somewhat. In fact, many of these weaknesses in PHP 5 have been resolved. Please keep an eye on it.
What PHP lacks in some areas, it can quickly make up for in the area of good. The price is reasonable, so you don't need to worry about licensing issues. It is also open source, so the entire community will keep a close eye on the development process: discovering bugs and fixing them. If there is a feature that you don't like, then you can modify the code. In addition, PHP can be combined with the Apache nature: it can be compiled as a module, or directly compiled into Apache binary files.
But running on Apache means that, with PHP, you can take advantage of the fact that you've invested in any server because Apache can run on Windows, Linux, Solaris, and a variety of other Unix platforms. In addition, using a Web server with Apache tracking records means that security can be maintained at the highest priority level. Finally, PHP has a smaller code path, which means less analysis and execution of PHP page server-side code, which leads to more efficient memory and usage and faster running.
What features are added to 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 errors have been identified and eliminated. Although it is still being tested, all of its new features and advances are indeed noteworthy.
The main new achievement of PHP 5 is its exception handling and a new object, the feature introduced by this new object gives PHP real OOP. Exception handling is undoubtedly one of the most significant flaws in PHP 4, and the introduction of PHP 5 to exception handling is certainly a sign of maturity. Exception handling means that you have a language-defined and standardized method of error handling in your software. With just the try, catch, and throw methods, your PHP code becomes more robust and concise.
<?phpclass 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 number of positive implications for 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 you must copy a copy of the object (all data structures in memory). This step uses memory, which slows access and congestion. In PHP 5, objects are usually passed by reference.
New object-oriented features in PHP 5, including constructors and destructors, are noteworthy. Like C + + and Java, they provide a standard way to create objects, allocate memory, and perform any necessary settings through a constructor method, and perform cleanup through a destructor method.
PHP 5 also introduces finer control over the methods and variables in the class. In PHP 4, everything is public: You can access variables in your class from outside the class or in an inherited class. In PHP 5, you can still make variables or methods public, but you can make them private so that you can use them only in the class itself. You can also protect them, that is, you can view methods and variables within a class or in a subclass.
In addition, PHP 5 introduces type hints or better type checking. When you pass an object to a routine, PHP can check that it is the correct type and produce a type mismatch error when the check fails.
Because there are other features (such as static methods and variables and abstract classes), be sure to review the documentation for more information.
Security comparisons
asp.net you are officially required to use IIS. Unfortunately, the history of the vulnerability of IIS has long been a long-standing one, which makes many administrators reluctant to deploy it to process Web sites. These weaknesses are due to Microsoft's flaws or the fact that IIS is the target of hackers ' attacks: these systems have a history of being hacked or hacked. PHP is also running on Apache, and Apache is fast and open source and has a good security record. In addition, as I mentioned, Apache can run on many platforms.
If you're thinking about asp.net, but you want to use Apache as an Internet portal, then you're lucky to have some choices. First, you can use Apache to send the request to IIS running inside the other computer. Apache then handles the static content and transmits the ASPX content to the IIS server (not exposed to the Internet).
However, if you want to take advantage of Apache hosting asp.net, there are options that Microsoft may or may not support. As a final option, there is Ximian Project Mono, which is dedicated to building an open source module. Please visit the http://www.go-mono.com/for more information.
Database Encoding Example
One of the first things you should consider when choosing PHP or asp.net is the connection to the database. However, using ASP.net is more complex because you can choose any language from a number of alternative languages. Of course, these code examples will have to be embedded in HTML pages, instantiated classes, and so on. However, the following information will give you an idea of the coding style of both.
PHP 5 with Oracle connection
The following is a PHP 5 class that provides an Oracle connection and disconnect routine to demonstrate a way to connect with Oracle using PHP 5, which can also use other drivers, such as ODBC drivers, and a common Database interface:
Class Oracle_object {
protected $theDB;
protected $user;
protected $pass;
protected $db;
function __construct ($u, $p, $d) {
$this->user = $u;
$this->pass = $p;
$this->db = $d;
}
function Db_open () {
$theDB = @OCILogon ($this->user, $this->pass, $this->db);
Db_check_errors ($php _errormsg);
}
function Db_close () {
@OCILogoff ($theDB);
Db_check_errors ($php _errormsg);
}
function __destruct () {
Print ("So long ...");
}
}
asp.net and Oracle connections
If you want to take advantage of VB. NET (Visual Basic is Microsoft's default. NET programming language) to connect to Oracle, take a look at this example from MSDN:
Imports System
Imports System.Data
Imports System.Data.OracleClient
Imports Microsoft.VisualBasic
Class Sample
Public Shared Sub Main ()
Dim oraconn as OracleConnection = New OracleConnection
("Data source=myoracleserver;integrated security=yes;")
Dim oracmd as OracleCommand = New OracleCommand
("Select customer_id, NAME from DEMO.") CUSTOMER ", Oraconn)
Oraconn.open ()
Dim myreader as OracleDataReader = Oracmd.executereader ()
Do while (Myreader.read ())
Console.WriteLine (VbTab & "{0}" & VbTab & "{1}",
Myreader.getint32 (0), myreader.getstring (1))
Loop
Myreader.close ()
Oraconn.close ()
End Sub
End Class

Make a choice
Assuming you haven't decided to use PHP yet, I can assert that PHP's advantages far outweigh its weaknesses. (See the Summary in Table 1.) These advantages come down to price, speed and efficiency, security, cross-platform applicability, and open source-code opportunities. Its only weakness is the lack of a pure and perfect OOP implementation, but this is a small drawback. Although the language structure does help, good coding is ultimately brought about by practice, execution, good habits and norms.
A comparison between PHP and ASP.net
Table 1
PHP 4 PHP5 asp.net
Software price free free of charge
Platform Price free Free $
Strong or weak speed
Strong or weak in efficiency
Security Qiangqiangqiang
Platform strength (for IIS only)
Any arbitrary Win32 on the platform (IIS only)
Whether the source code is provided is whether
Whether the exception is
OOP weak powerful
Price
Here, we should not simply consider the initial investment-which is obviously free for PHP-and should also consider the cost of implementation, maintenance, and debugging. For PHP, you may need to purchase the Zend optimization engine. However, with ASP, you will be investing from the start, and you'll have to pay for the additional technology-for example, the library that performs graphics processing. However, in the long run, PHP will not force you to upgrade and charge you more license fees. Everyone who has contacted a complex license knows that many companies spend a lot of time and money just to ensure their compliance. In addition, you get a different response when you get the bug fix time. This will of course translate into time, and time will turn into the cost of overall development.
Speed and efficiency
As I mentioned earlier, ASP.net is a framework that allows you to use a variety of programming languages. In addition, it is said to have an excellent object-oriented model. Although all of this is true, it is unfavorable when considering the speed. For these reasons, running an ASP page in asp.net requires more code than running the equivalent PHP page in the PHP engine. PHP is a "quick and rough" solution, a solution designed to get the job done. Although it has enhanced many robustness since versions 2.0 and 3.0, it still retains the core of the high speed approach to optimization.
Speed is not the only factor to consider. Memory usage is also important.
Security
asp.net runs on IIS, and IIS has been attacked countless times-as confirmed by the IT News report every other week. It has become such a burden that, in fact, despite its huge cost of sales promotion, many IT professionals still refuse to use the IIS Web server to open their networks. and PHP uses Apache. Apache has proven record of speed, reliability, and solid security. Please visit the http://www.securityfocus.com/for more information.
Cross-platform applicability
asp.net runs on IIS and starts running on Apache (Apache can run on many platforms). PHP was designed to work with Apache from the outset, so you have a number of proven and reliable server platforms to choose from.
Open Source Code Opportunities
Open source code is not only done by some whimsical programmers or companies that want to save some license fees. Open source code can be a real godsend when you're dealing with bugs in the software itself.
In the case of using PHP or asp.net, you will have a large user base that uses the software and may encounter errors. Using ASP.net, these errors must be notified, repaired, tested, and eliminated in a new patch or version through an official program. However, the PHP patches can be quickly patched and released. Anyone who has witnessed open source development knows that new versions and patches are usually launched in a matter of days rather than commercial software in a few weeks or months. If this is not fast enough, you can usually fix the problem yourself (if necessary).
The advantages of PHP in the field of web development
Your current position: Du demon old--> technical document Complete works in the eyes of most Web developers, both ASP and JSP are considered to be the front-runner, while PHP is considered a weak "struggling" or a language that is devalued as an amateur, and is not worth participating in the competition of enterprise web development. In my opinion, the reason that PHP is not considered a competitor is that commentators lack knowledge of it and other operating systems for Web development. Contrary to some ideas, windows no longer occupies the largest share of the Web virtual host services market, and I suspect it is also being destroyed in the area of web development.
Why is there no PHP in enterprise development?
Obviously, PHP is considered to be behind the ASP and JSP too much, so that it is useless, but this is not exactly the truth. PHP itself is a powerful language. It's actually available on every Linux distribution, on Mac OS X as well. Get the widget (Building-block) tools and software for developing and using PHP code for free. A business integrated development environment for developing PHP applications (commercial integrated DEVELOPMENT environments, IDES) can also find such tools as Komodo (which runs on Linux and Windows) and Zend STUDIO (this application can run on any operating system with a Java running environment). The fact that you can run a Web site built by PHP on almost every web virtual host without considering what operating system the server is running makes PHP more appealing.
What can PHP offer?
Let's forget about PHP for a while and consider what PHP can offer itself. It is a robust server-side language that provides a considerable amount of functionality and is able to quickly serve pages.
Easy to use
Any user who uses C or Perl or another language with a similar style and syntax can quickly start PHP. Although it is designed for use on the web, it can also be used as a command-line language. Does the Web application you are writing need to execute some code every hour or every day? Using cron or a similar scheduling manager, you can plan to schedule PHP code to execute when you want, using a normal command interpretation script or a batch file to execute the code. You do not need to automatically call the browser to view a dedicated Web page to perform your event, nor do you need to rely on a visitor's click to tell your system that specific code needs to be executed at a specific time. The fact that PHP is extensible in this area is absolutely appealing.
The benefits of PHP
I am not a JSP or a veteran of ASP, here I do not want to belittle these languages. Instead, I'll focus on the benefits of PHP.
Localization
PHP allows you to provide localized services to visitors to your site. When the user clicks into the site, the site will automatically provide the page in their native language according to their browser settings. This does not require the use of tumultuous files for language translation, but rather the same capabilities that are used with localized C programs, implemented through a system called GetText. If the requested language file exists, the text that the user sees is his or her native language, and if the language file does not exist, the text is the default English or any other language you specify. Many localized UNIX applications use GetText as a standard, making it easy for third parties to translate.
Easy to use command line
PHP supports setting up and executing command-line programs where needed. Using the standard UNIX diff tool, it can generate the difference between the last modification of an error and the current annotation to be sent to the owner of the error by using an e-mail message. The PHP code performs a DIFF on the two files written on the system, outputting its output as input and regenerating it into an e-mail message to be sent. This email is sent through PHP itself.
Other benefits
It's just two of the powerful features I've used in my program, and other features. For example, you can:
Create simple Flash animations on the fly.
Create a PDF document on the fly.
Use advanced math features, as well as object-oriented programming techniques.
Read and write to local and IMAP mailboxes.
You can use any standard Internet protocol in PHP. Want to write a PHP based FTP, Web, or news client? No problem! Using PHP alone, you can create your own protocol by writing a client and server that uses a standard TCP/IP socket.
Implement support for encryption and support for various database servers.
A lack of visionary commentary
I think those who are looking for top-tier Web development languages and get rid of PHP are extremely short-sighted. I've been writing code in PHP for years, whether it's advanced features like bug-tracking systems, or simply reusing common features like headers and footers, I've written in PHP. I used PHP to write more than half static pages, but also wrote a full-featured multimedia demo. I'm not the only one who uses PHP. If PHP is not worth noticing, if it's just a pediatric or hobbyist language, why is it the fastest growing language on Web development? If it's not as powerful as an ASP or JSP, why is it being used on a huge traffic web site? Yahoo, for example, is said to have been built by PHP.
Developers are accustomed to using familiar products
I'm sure that ASP and JSP have their own strengths, but I believe people use them not because they can provide more powerful functionality than PHP, but because people already know them and want to write code in their own way. Excluding PHP can only express ignorance of the language.
Related Article

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.