php asp net interoperability rc jao

26
Rodney C. Jao Rodney C. Jao Microsoft MVP for Device Application Microsoft MVP for Device Application Development Development

Upload: jedt

Post on 13-May-2015

3.508 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Php Asp Net Interoperability Rc Jao

Rodney C. JaoRodney C. JaoMicrosoft MVP for Device Application DevelopmentMicrosoft MVP for Device Application Development

Page 2: Php Asp Net Interoperability Rc Jao

AgendaAgenda

PHP in IIS7PHP in IIS7

PHP-ASP.NET Interoperability using SOAPPHP-ASP.NET Interoperability using SOAP

Page 3: Php Asp Net Interoperability Rc Jao

Why this session?Why this session?

A large number of PHP basedA large number of PHP based business business applicationsapplications are running on Windows Servers are running on Windows Servers

Discuss the recent developments on running Discuss the recent developments on running PHP applications on Windows Server PHP applications on Windows Server

Leverage existing code investments in PHP and Leverage existing code investments in PHP and ASP.NET via interoperabilityASP.NET via interoperability

Take advantage of SOAP to extend web Take advantage of SOAP to extend web applications and integrate regardless of applications and integrate regardless of language and platform.language and platform.

Page 4: Php Asp Net Interoperability Rc Jao

PHP in Windows ServerPHP in Windows Server

PHP runs on Windows Server via Microsoft PHP runs on Windows Server via Microsoft Internet Information ServerInternet Information Server

IIS 7 in Windows Server 2008 SP2IIS 7 in Windows Server 2008 SP2

IIS 7.5 in Windows Server 2008 R2IIS 7.5 in Windows Server 2008 R2

Execution ModelsExecution Models

Traditional model is based on instantiating PHP for Traditional model is based on instantiating PHP for every session (CGI)every session (CGI)

Later released an ISAPI version for faster Later released an ISAPI version for faster execution.execution.

Page 5: Php Asp Net Interoperability Rc Jao

ISAPIISAPICGICGI

IIS Execution Models for PHPIIS Execution Models for PHP

IISIIS

PHPPHP PHPPHP

PHPPHP

ISAPI

PHPPHP

PHP executes as an external process.

Stable however there’s a challenge in performance.

IIS

PHP as In-process.

Speeds up performance but issues on non thread safe extensions.

Page 6: Php Asp Net Interoperability Rc Jao

IIS Execution ModelsIIS Execution Models

Extension to CGI allowing reuse of a process.

Advantages

Easy to Configure

Faster than CGI

More stable than

PHP on ISAPI

Can run non-

thread-safe

versions of PHP

Invokes a process for each request.

Advantages

Easy to Configure

Stable Execution

Disadvantages

Slow due to I/O

Overhead of

Process Creation

Loaded as extension in process.

Advantages

Better Performance

Disadvantages

Many PHP

Applications are

not Thread-Safe

Page 7: Php Asp Net Interoperability Rc Jao

Introduction: FastCGIIntroduction: FastCGI

FastCGI is an enhancement to the CGI modelFastCGI is an enhancement to the CGI model

High performance PHP applications on Windows High performance PHP applications on Windows ServerServer

Reusable pool of processesReusable pool of processes

No startup and shutdown for each PHP sessionNo startup and shutdown for each PHP session

Stable execution of non thread safe PHP extensionsStable execution of non thread safe PHP extensions

Available for IIS 6 (Windows Server 2003), IIS 7 Available for IIS 6 (Windows Server 2003), IIS 7 (Windows Server 2008 SP2), and IIS 7.5 (Windows Server 2008 SP2), and IIS 7.5 (Windows Server 2008 R2)(Windows Server 2008 R2)

Page 8: Php Asp Net Interoperability Rc Jao

Setting up PHP and FastCGISetting up PHP and FastCGI

Enable FastCGI in IISEnable FastCGI in IIS

Do Windows Update – for latest fix and patchesDo Windows Update – for latest fix and patches

Download the latest edition of PHPDownload the latest edition of PHP

Unzip to desired destination folderUnzip to desired destination folder

Open PHP.INIOpen PHP.INI

fastcgi.impersonate = 1fastcgi.impersonate = 1

cgi.fix_pathinfo=1cgi.fix_pathinfo=1

cgi.force_redirectcgi.force_redirect = 0 = 0

extension_dirextension_dir

Uncomment extensions (php_soap.dll)Uncomment extensions (php_soap.dll)

Page 9: Php Asp Net Interoperability Rc Jao

Setting up PHP and FastCGISetting up PHP and FastCGI

Configure IIS to Configure IIS to handle PHPhandle PHP

IIS Manager – IIS Manager – Handler MappingsHandler Mappings

Set PHP Process Set PHP Process Recycling behaviorRecycling behavior

PHP_FCGI_MAX_REQUESTSPHP_FCGI_MAX_REQUESTS

Page 10: Php Asp Net Interoperability Rc Jao

DEMO DEMO Setting up PHP and FastCGI in IIS7Setting up PHP and FastCGI in IIS7

Page 11: Php Asp Net Interoperability Rc Jao

Microsoft Web Platform InstallerMicrosoft Web Platform Installer

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

http://www.microsoft.com/web

Page 12: Php Asp Net Interoperability Rc Jao

DEMO DEMO Web Platform InstallerWeb Platform Installer

Page 13: Php Asp Net Interoperability Rc Jao

WinCacheWinCache

PHP accelerator to speed up PHP applications PHP accelerator to speed up PHP applications in Windows – without code rewritein Windows – without code rewrite

PHP Opcode CachePHP Opcode Cache

File CacheFile Cache

Relative File Path CacheRelative File Path Cache

Page 14: Php Asp Net Interoperability Rc Jao

PHP-ASP.NET InteroperabilityPHP-ASP.NET Interoperability

Why SOAP?Why SOAP?

Simple Object Access ProtocolSimple Object Access Protocol

SOAP is a standardSOAP is a standard

Based on XMLBased on XML

Exists on almost every platformExists on almost every platform

FlexibleFlexible

Firewall friendlyFirewall friendly

Invoking methods via xml messagesInvoking methods via xml messages

Pass / return data (integers, decimal, string, classes, objects, Pass / return data (integers, decimal, string, classes, objects, images, etc) via xml images, etc) via xml

Enabler for Service Oriented ArchitectureEnabler for Service Oriented Architecture

Page 15: Php Asp Net Interoperability Rc Jao

How SOAP worksHow SOAP works

Client Server

Determine Service

Method call (xml)

Server response (xml)

Page 16: Php Asp Net Interoperability Rc Jao

SOAPSOAP

ComponentsComponents

WSDL – Web Service Definition Language (also WSDL – Web Service Definition Language (also called a contract)called a contract)

Describes the server data, methods, and portsDescribes the server data, methods, and ports

SOAP DataSOAP Data

SOAP MethodsSOAP Methods

Page 17: Php Asp Net Interoperability Rc Jao

DEMODEMOWSDL and Web Service in ASP.NETWSDL and Web Service in ASP.NET

Page 18: Php Asp Net Interoperability Rc Jao

SOAP in PHPSOAP in PHP

As PHP extensionAs PHP extension

Writen in CWriten in C

[PHP_SOAP][PHP_SOAP]

extension=php_soap.dllextension=php_soap.dll

Using API’s written in PHPUsing API’s written in PHP

PEAR::SOAP (http://pear.php.net) PEAR::SOAP (http://pear.php.net)

NuSOAP (http://dietrich.ganx4.com/nusoap) NuSOAP (http://dietrich.ganx4.com/nusoap)

eZ SOAP (http://ez.no) eZ SOAP (http://ez.no)

Page 19: Php Asp Net Interoperability Rc Jao

Consuming Web Services in PHPConsuming Web Services in PHP

Use SoapClientUse SoapClient<?php<?php

$client = new soapclient("http://myserver/service.svc?wsdl");$client = new soapclient("http://myserver/service.svc?wsdl");

$ret = $client->$ret = $client->HelloWorldHelloWorld();();

echo "from ws = " . $ret->echo "from ws = " . $ret->HelloWorldResultHelloWorldResult;;

?>?>

XML messages are hiddenXML messages are hidden

Call SOAP methods as if they are PHP functionsCall SOAP methods as if they are PHP functions

Page 20: Php Asp Net Interoperability Rc Jao

DEMODEMOConsuming Web Services in PHPConsuming Web Services in PHP

Page 21: Php Asp Net Interoperability Rc Jao

WSDL CachingWSDL Caching

Improving SOAP call performanceImproving SOAP call performance

[soap] [soap]

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

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

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

Page 22: Php Asp Net Interoperability Rc Jao

Creating SOAP Services in PHPCreating SOAP Services in PHP

Create your SOAP service WSDLCreate your SOAP service WSDL

Define your SOAP data and methodsDefine your SOAP data and methods<?php <?php

function add(int $x, int $y) { function add(int $x, int $y) {

return $x+$y;return $x+$y;

} }

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

$server = new SoapServer("myservice.wsdl"); $server = new SoapServer("myservice.wsdl");

$server->addFunction("add"); $server->addFunction("add");

$server->handle(); $server->handle();

?>?>

Replace addFunction() with setClass() to expose classesReplace addFunction() with setClass() to expose classes

Page 23: Php Asp Net Interoperability Rc Jao

DEMODEMOConsuming PHP SOAP Service in ASP.NETConsuming PHP SOAP Service in ASP.NET

Page 24: Php Asp Net Interoperability Rc Jao

What Next?What Next?

Download Microsoft Web Platform InstallerDownload Microsoft Web Platform Installer

Run PHP Applications in FastCGI + WinCacheRun PHP Applications in FastCGI + WinCache

Run your production PHP web applications in Run your production PHP web applications in Windows ServerWindows Server

Integrate and interoperate existing systems Integrate and interoperate existing systems using SOAPusing SOAP

Page 25: Php Asp Net Interoperability Rc Jao

ResourcesResourceshttp://learn.iis.net

http://www.asp.net

http://www.microsoft.com/web

BizSpark and Website SparkBizSpark and Website Spark

http://devzone.zend.comhttp://devzone.zend.com

Page 26: Php Asp Net Interoperability Rc Jao