php-asp by wulinqing

VIEWS: 8 PAGES: 23

									 PHP and ASP.NET

Pros and Cons of the two most
popular means of building web
         applications




                                1
            PHP and ASP.NET
For Web development, there are a lot of options. Many of
these methods involve preprocessing. This code is then run
on the server, and it returns some content. Both the open
source scripting language PHP and languages within
Microsoft's ASP.NET framework fall into this category; JSP
and Perl/Mason operate this way as well.

PHP, the technology Oracle has chosen to incorporate into its
products, and ASP.NET. Overview of various strengths and
weaknesses are discussed.

Finally, a point-by-point comparison in terms of price, speed
and efficiency, security, cross-platform support, and the
advantages of an open source solution.




                                                            2
                         ASP.NET
What is ASP.NET?
ASP.NET is a complete rewrite of the software. Previous ASP technology
actually has a lot more in common with PHP than with ASP.NET, which is
a complete framework for building Web applications. One of the main
features of this model is the flexibility to choose PL. ASP.NET works with
scripted 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 ; your
language source is compiled into MIL code, which the CLR then executes.

The framework also provides for OOP, inheritance, polymorphism, and
encapsulation are supported. The .NET class library is organized into
inheritable classes based around particular tasks, such as working with
XML or image manipulation.

When you program in ASP.NET, integration with databases can be
accomplished through ODBC, which provides a set of calling functions to
access your database.


                                                                    3
    Strengths and Weaknesses
ASP.NET's strength

    – Design and implementation
    – Language flexibility, and object-oriented features
       supported.
    – Development environment.
(Developers can use WebMatrix, Visual Studio .NET, or various
Borland tools such as Delphi and C++ Builder. Visual Studio,
for instance, allows setting of breakpoints, tracing sections of
code. It's a sophisticated debugging environment. )

Weaknesses:
Expensive with respect to memory usage and execution time.
 (For Web-based applications, these limitations can be a
serious problem, because on the Web, your application is
likely to scale to thousands and thousands of users/second.
Memory usage can also become an issue on your Web server.)

                                                               4
                  What is PHP?
PHP is a scripting language based on the model of preprocessing
HTML pages. When the PHP preprocessor in Web server notices a
PHP language tag, the PHP engine is invoked to execute that
code.

PHP will be familiar to anyone who has worked with imperative
PLs; syntactical similarities with Perl, C, and Java. Strictly
speaking, Java is an imperative programming language, but it also
makes use of object-oriented constructs and concepts. PHP
borrows from this structure when it is convenient, but it is not a
pure OOP language.

You can use ODBC to talk to databases. There are also native
drivers for MySQL, Oracle, and Postgres. If you are connecting to
Oracle, a special OCI8 library provides more feature-rich access to
Oracle, allowing you to use such features as LOB, BLOB, CLOB,
and BFILE.


                                                              5
             What is PHP?
Zend Technologies, a commercial s/w that
contributes significantly to PHP, has created
a commercial-development environment
called Zend Studio that includes a
sophisticated debugger, a profiler, and other
features. It has also built the free Zend
Optimizer, which, in combination with the
Zend Encoder, compiles PHP code to speed
performance.       Additional     commercial
products also exist, such as the Zend
Performance Suite, which can cache
precompiled PHP pages, further speeding
overall performance tremendously.
                                            6
    Strengths and Weaknesses
PHP 5
Lack of exceptions, event-based error-handling instances.
(Java provides exceptions for error handling, while C++
provides exception handling via the try, catch, and throw
syntax).
You can still manage errors in PHP, but the structure is not
standardized, so programmers are left to their own devices on
how to implement error handling, leading to less consistency.

PHP's function names are case insensitive (this isn't a serious
drawback).

PHP wasn't designed to be an object-oriented language. Some
of those features were added later, although care was made to
keep backward compatibility with PHP 3, so you're left with a
bit of both models. In fact, many of these weaknesses are
addressed in PHP 5.

                                                              7
    Strengths and Weaknesses
Price is right, so you don't have to worry about licensing
issues.
open source -so an entire community will keep a close eye on
development, identifying bugs and making sure they get fixed.
PHP works native with Apache: It can be compiled as a
module or directly into the Apache binary.

Running on Apache means that, with PHP, you can take
advantage of whatever server investments you've already
made, because Apache runs on Windows, Linux, Solaris, and
various other Unix platforms. Also, going with a web server
with Apache's track record means security remains a top
priority.

PHP has a smaller code path, ie there's less server-side code
executed to parse and execute your PHP page, which results
in more efficient memory and usage and faster execution.
                                                            8
      What's New in PHP 5?

New features
•Exception handling
•OOP

Exception handling was certainly one of the
most noticeable missing features in PHP 4,
and is added to PHP 5. Exception handling
means you have language defined and
standardized ways of handling errors. Use
the try, catch, and throw methods, and your
PHP code becomes more robust and clean.

                                          9
                                                    PH5
<?php
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
?>
                                                          10
         What's New in PHP 5?
Object model
In PHP 4, when an object was passed to a function or method,
it was passed by value, unless you explicitly told PHP
otherwise. This procedure meant that a copy of that object, all
the data structures in memory, would have to be copied. This
step used memory and made access slow. In PHP 5, objects
are always passed by reference.

•object-oriented features in PHP 5, including constructors and
destructors. As with C++ and Java, they provide a standard
way to create the object, allocate memory, and do any
necessary setup via a constructor method and perform
cleanup with a destructor method.




                                                             11
         What's New in PHP 5?
PHP 5 introduces more subtle control of methods and
variables in classes. In PHP 4, everything was public: You
could access variables from your classes outside the class or
in derived classes. In PHP 5, you can still make variables or
methods public, but you can also make them private, so
they're used only within the class itself. A third option is to
make them protected, which means that methods and
variables can be viewed within the class or when subclassed.

•PHP 5 introduces type checking. When you pass an object
into a routine, PHP can check that it is the right type and give
a type-mismatch error if the check fails.

•Additional features such as static methods and variables and
abstract classes exist.



                                                              12
       Security Comparison

ASP.NET officially requires that you
use IIS.

PHP runs on Apache, too, which is fast
and open source and has a good
security track record. Also, Apache
runs on many platforms.

                                       13
      Database Connectivity

With ASP.NET, it's a little more
complicated, because you have the option
of a number of languages to choose from.
These code samples would have to be
embedded into an HTML page, the classes
instantiated, and so on.



                                     14
                                     Coding styles
PHP 5 Connecting to Oracle
PHP 5 class that provides an Oracle connect-and-
disconnect routine to show one way of connecting to
Oracle with PHP 5 (other drivers, such as the ODBC
driver, and generic database interfaces can be used as
well):
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...");                                      15
  }
}
        ASP.NET Connecting to
               Oracle
Connect to Oracle with VB.NET (VB is Microsoft's default
.NET programming language)
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
                                                                               16
            Making the Choice
PHP, its strengths outweigh its weaknesses.
   – Strength
   – Price
   – Speed and efficiency
   – Security
   – Cross-platform applicability
   – Open-source opportunity
Weakness
Lack of a pure and perfect OOP implementation

Though language constructs do help, ultimately, good coding is a
  matter of practice, execution, good habits, and discipline.


                                                                   17
                   Making the Choice
                    PHP 4    PHP 5     ASP.NET
S/W price           Free     Free      Free
Platform price      Free     Free      $$
Speed               Strong   Strong    Weak
Efficiency          Strong   Strong    Weak
Security            Strong   Strong    Strong
Platform            Strong   Strong    Weak(IIS only)
Platform            Any      Any       Win32(IIS only)
Source available    Yes      Yes       no
Exceptions          No       No        yes
                                                 18
OOP                 Weak     Strong    strong
                           Price
Price tag of the initial investment –PHP free
Implementation, maintenance, and debugging costs.

PHP, you may invest in the Zend optimization engine.
PHP isn't going to press you to upgrade.

ASP, you're investing from the very beginning, and you're
spending for add-on technologies—libraries for doing
graphics manipulations, for instance.

Companies spend time and money just ensuring they are
compliant.




                                                            19
           Speed and efficiency
ASP.NET is a framework allowing you to use various PL. In
addition, it has a great object-oriented model. But it becomes a
detriment as far as speed is concerned. For all that advantage,
there is a lot more code to run through to execute the same
ASP page than you have to execute in the PHP engine for an
equivalent PHP page.

PHP is the quick type of solution, the one to get the job done.
A lot of robustness has been added to it since its 2.0 and 3.0
days, it still retains that core optimized high-speed approach.

Speed is not the only consideration. Memory usage is also
important.




                                                              20
                 Security

ASP.NET runs on IIS, which has been
compromised innumerable times. It has
become such a liability, in fact, many IT
professionals refuse to have their networks
exposed with an IIS Web server.

PHP, however, works with Apache, which has a
proven track record of speed, reliability, and
security.

                                          21
      Cross-platform applicability

ASP.NET runs on IIS and is starting to run on
Apache, which can run on a whole host of
platforms.

PHP has been designed to work with Apache
from the beginning, so you have many proven
and reliable server platforms to choose from.

                                         22
                      Open source
Open source is not just companies wanting to save a few bucks on
licensing costs. When you're dealing with bugs in the software
itself, open source can be a serious godsend.

In either case, with PHP or ASP.NET, you have a large user base
using the s/w. With ASP.NET, those bugs have to go through a
bureaucratic process to get acknowledged, fixed, tested, and rolled
out in a new patch or release. PHP fixes, however, can get fixed
quickly and rereleased.

For Open-source development, new releases and patches often
come out in days rather than in weeks or months, as with
commercial software. If that's not fast enough, you can always fix a
problem yourself if you have to.




                                                               23

								
To top