DEMO - Rodney by zhouwenjuan

VIEWS: 0 PAGES: 26

									PHP-ASP.NET Interoperability



Rodney C. Jao
Microsoft MVP for Device Application Development
Agenda

PHP in IIS7
PHP-ASP.NET Interoperability using SOAP
Why this session?

 A large number of PHP based business
 applications are running on Windows Servers
 Discuss the recent developments on running
 PHP applications on Windows Server
 Leverage existing code investments in PHP and
 ASP.NET via interoperability
 Take advantage of SOAP to extend web
 applications and integrate regardless of
 language and platform.
PHP in Windows Server

 PHP runs on Windows Server via Microsoft
 Internet Information Server
    IIS 7 in Windows Server 2008 SP2
    IIS 7.5 in Windows Server 2008 R2
 Execution Models
    Traditional model is based on instantiating PHP for
    every session (CGI)
    Later released an ISAPI version for faster
    execution.
IIS Execution Models for PHP

  CGI                          ISAPI
          PHP
                                         PHP
  PHP            PHP


                                          ISAPI
           IIS                             IIS

PHP executes as an external   PHP as In-process.
process.
                              Speeds up performance but
Stable however there’s a      issues on non thread safe
challenge in performance.     extensions.
IIS Execution Models



Invokes a process for each   Loaded as extension in   Extension to CGI allowing
         request.                  process.              reuse of a process.


      Advantages                 Advantages                 Advantages
    Easy to Configure          Better Performance         Easy to Configure
     Stable Execution                                      Faster than CGI
                                Disadvantages             More stable than
     Disadvantages                 Many PHP                  PHP on ISAPI
      Slow due to I/O            Applications are           Can run non-
       Overhead of               not Thread-Safe              thread-safe
      Process Creation                                      versions of PHP
Introduction: FastCGI

 FastCGI is an enhancement to the CGI model
     High performance PHP applications on Windows
     Server
     Reusable pool of processes
     No startup and shutdown for each PHP session
     Stable execution of non thread safe PHP extensions
 Available for IIS 6 (Windows Server 2003), IIS 7
 (Windows Server 2008 SP2), and IIS 7.5
 (Windows Server 2008 R2)
Setting up PHP and FastCGI

 Enable FastCGI in IIS
     Do Windows Update – for latest fix and patches
 Download the latest edition of PHP
     Unzip to desired destination folder
 Open PHP.INI
     fastcgi.impersonate = 1
     cgi.fix_pathinfo=1
     cgi.force_redirect = 0
     extension_dir
     Uncomment extensions (php_soap.dll)
Setting up PHP and FastCGI

 Configure IIS to
 handle PHP
     IIS Manager –
     Handler Mappings
 Set PHP Process
 Recycling behavior
     PHP_FCGI_MAX_REQUESTS
Setting up PHP and FastCGI in IIS7

DEMO
 Microsoft Web Platform Installer

                               Downloads and
                               configures your web
                               server, database, and
                               tools needed to
                               develop and run web
                               applications.




http://www.microsoft.com/web
Web Platform Installer

DEMO
WinCache

 PHP accelerator to speed up PHP applications
 in Windows – without code rewrite
    PHP Opcode Cache
    File Cache
    Relative File Path Cache
PHP-ASP.NET Interoperability

 Why SOAP?
     Simple Object Access Protocol
     SOAP is a standard
     Based on XML
     Exists on almost every platform
     Flexible
     Firewall friendly
 Invoking methods via xml messages
 Pass / return data (integers, decimal, string, classes,
 objects, images, etc) via xml
 Enabler for Service Oriented Architecture
How SOAP works

           Determine Service


          Method call (xml)
 Client                           Server

          Server response (xml)
SOAP

 Components
    WSDL – Web Service Definition Language (also
    called a contract)
       Describes the server data, methods, and ports
    SOAP Data
    SOAP Methods
WSDL and Web Service in ASP.NET

DEMO
SOAP in PHP

 As PHP extension
     Writen in C
  [PHP_SOAP]
  extension=php_soap.dll

 Using API’s written in PHP
     PEAR::SOAP (http://pear.php.net)
     NuSOAP (http://dietrich.ganx4.com/nusoap)
     eZ SOAP (http://ez.no)
Consuming Web Services in PHP

 Use SoapClient
  <?php
  $client = new soapclient("http://myserver/service.svc?wsdl");
  $ret = $client->HelloWorld();
  echo "from ws = " . $ret->HelloWorldResult;
  ?>

 XML messages are hidden
 Call SOAP methods as if they are PHP functions
Consuming Web Services in PHP

DEMO
WSDL Caching

 Improving SOAP call performance

  [soap]

  soap.wsdl_cache_enabled = "1"
  ; enables or disables WSDL caching feature

  soap.wsdl_cache_dir = "/tmp"
  ; sets the directory name where SOAP extension will put cache files

  soap.wsdl_cache_ttl = "86400"
  ; (time to live) sets the number of second while cached file will be used
  ; instead of original one
Creating SOAP Services in PHP

 Create your SOAP service WSDL
 Define your SOAP data and methods
  <?php
  function add(int $x, int $y) {
      return $x+$y;
  }
  ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
  $server = new SoapServer("myservice.wsdl");
  $server->addFunction("add");
  $server->handle();
  ?>

 Replace addFunction() with setClass() to expose classes
Consuming PHP SOAP Service in ASP.NET

DEMO
What Next?

 Download Microsoft Web Platform Installer
 Run PHP Applications in FastCGI + WinCache
 Run your production PHP web applications in
 Windows Server
 Integrate and interoperate existing systems
 using SOAP
Resources
 http://learn.iis.net
 http://www.asp.net
 http://www.microsoft.com/web
 BizSpark and Website Spark
 http://devzone.zend.com

								
To top