SlideShare a Scribd company logo
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.
ISAPI CGI IIS Execution Models for PHP IIS PHP PHP PHP PHP 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. ISAPI
IIS 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
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
DEMO  Setting up PHP and FastCGI in IIS7
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
DEMO  Web Platform Installer
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 Client Server Determine Service Method call (xml) 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
DEMO WSDL and Web Service  in ASP.NET
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(&quot;http://myserver/service.svc?wsdl&quot;); $ret = $client-> HelloWorld (); echo &quot;from ws = &quot; . $ret-> HelloWorldResult ; ?> XML messages are hidden Call SOAP methods as if they are PHP functions
DEMO Consuming Web Services in PHP
WSDL Caching Improving SOAP call performance [soap]  soap.wsdl_cache_enabled = &quot;1&quot;  ; enables or disables WSDL caching feature  soap.wsdl_cache_dir = &quot;/tmp&quot;  ; sets the directory name where SOAP extension will put cache files  soap.wsdl_cache_ttl = &quot;86400&quot;  ; (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(&quot;soap.wsdl_cache_enabled&quot;, &quot;0&quot;); // disabling WSDL cache  $server = new SoapServer(&quot;myservice.wsdl&quot;);  $server->addFunction(&quot;add&quot;);  $server->handle();  ?> Replace addFunction() with setClass() to expose classes
Writing  WSDL Sections Definition Message  Port type Binding <?xml version ='1.0' encoding ='UTF-8' ?>  < definition s  name='StockQuote'  targetNamespace='http://example.org/StockQuote' /'>  < message  name='getQuoteRequest'>  <part name='symbol' type='xsd:string'/> </message>  < message  name='getQuoteResponse'>  <part name='Result' type='xsd:float'/> </message>  < portType  name='StockQuotePortType'>  <operation name='getQuote'>  <input message='tns:getQuoteRequest'/>  <output message='tns:getQuoteResponse'/>  </operation>  </portType>  < bindin g  name='StockQuoteBinding' type='tns:StockQuotePortType'>  <soap:binding style='rpc'  transport='http://schemas.xmlsoap.org/soap/http'/>  <operation name='getQuote'>  <soap:operation soapAction='urn:xmethods-delayed-quotes#getQuote'/>  <input> <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'  encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </input>  <output> <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'  encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </output>  </operation>  </binding>  <service name='StockQuoteService'>  <port name='StockQuotePort' binding='StockQuoteBinding'>  <soap:address location='http://[insert real path here]/server1.php'/> </port> </service>  </definitions>
DEMO Consuming PHP SOAP Service in ASP.NET
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
 

More Related Content

Php Asp Net Interoperability Rc Jao

  • 1. Rodney C. Jao Microsoft MVP for Device Application Development
  • 2. Agenda PHP in IIS7 PHP-ASP.NET Interoperability using SOAP
  • 3. 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.
  • 4. 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.
  • 5. ISAPI CGI IIS Execution Models for PHP IIS PHP PHP PHP PHP 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. ISAPI
  • 6. IIS 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
  • 7. 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)
  • 8. 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)
  • 9. Setting up PHP and FastCGI Configure IIS to handle PHP IIS Manager – Handler Mappings Set PHP Process Recycling behavior PHP_FCGI_MAX_REQUESTS
  • 10. DEMO Setting up PHP and FastCGI in IIS7
  • 11. 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
  • 12. DEMO Web Platform Installer
  • 13. WinCache PHP accelerator to speed up PHP applications in Windows – without code rewrite PHP Opcode Cache File Cache Relative File Path Cache
  • 14. 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
  • 15. How SOAP works Client Server Determine Service Method call (xml) Server response (xml)
  • 16. SOAP Components WSDL – Web Service Definition Language (also called a contract) Describes the server data, methods, and ports SOAP Data SOAP Methods
  • 17. DEMO WSDL and Web Service in ASP.NET
  • 18. 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)
  • 19. Consuming Web Services in PHP Use SoapClient <?php $client = new soapclient(&quot;http://myserver/service.svc?wsdl&quot;); $ret = $client-> HelloWorld (); echo &quot;from ws = &quot; . $ret-> HelloWorldResult ; ?> XML messages are hidden Call SOAP methods as if they are PHP functions
  • 20. DEMO Consuming Web Services in PHP
  • 21. WSDL Caching Improving SOAP call performance [soap] soap.wsdl_cache_enabled = &quot;1&quot; ; enables or disables WSDL caching feature soap.wsdl_cache_dir = &quot;/tmp&quot; ; sets the directory name where SOAP extension will put cache files soap.wsdl_cache_ttl = &quot;86400&quot; ; (time to live) sets the number of second while cached file will be used ; instead of original one
  • 22. 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(&quot;soap.wsdl_cache_enabled&quot;, &quot;0&quot;); // disabling WSDL cache $server = new SoapServer(&quot;myservice.wsdl&quot;); $server->addFunction(&quot;add&quot;); $server->handle(); ?> Replace addFunction() with setClass() to expose classes
  • 23. Writing WSDL Sections Definition Message Port type Binding <?xml version ='1.0' encoding ='UTF-8' ?> < definition s name='StockQuote' targetNamespace='http://example.org/StockQuote' /'> < message name='getQuoteRequest'> <part name='symbol' type='xsd:string'/> </message> < message name='getQuoteResponse'> <part name='Result' type='xsd:float'/> </message> < portType name='StockQuotePortType'> <operation name='getQuote'> <input message='tns:getQuoteRequest'/> <output message='tns:getQuoteResponse'/> </operation> </portType> < bindin g name='StockQuoteBinding' type='tns:StockQuotePortType'> <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/> <operation name='getQuote'> <soap:operation soapAction='urn:xmethods-delayed-quotes#getQuote'/> <input> <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </input> <output> <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </output> </operation> </binding> <service name='StockQuoteService'> <port name='StockQuotePort' binding='StockQuoteBinding'> <soap:address location='http://[insert real path here]/server1.php'/> </port> </service> </definitions>
  • 24. DEMO Consuming PHP SOAP Service in ASP.NET
  • 25. 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
  • 26. Resources http://learn.iis.net http://www.asp.net http://www.microsoft.com/web BizSpark and Website Spark http://devzone.zend.com
  • 27.  

Editor's Notes

  1. Show URL Rewrite (for mod_rewrite) Show WinCache Show Database Manager extension Show running wordpress – permalinks set on web.config
  2. PHP Opcode Cache PHP is a script processing engine that reads an input stream of data that contains text and/or PHP instructions and produces another stream of data, most commonly in the HTML format. This means that on a Web server, the PHP engine reads, parses, compiles, and executes a PHP script each time that it is requested by a Web client. The reading, parsing, and compilation operations put additional load on the Web server’s CPU and file system and thus affect the overall performance of a PHP Web application. The PHP bytecode (opcode) cache is used to store the compiled script bytecode in shared memory so that it can be reused by the PHP engine for subsequent executions of the same script. File Cache Even with the PHP bytecode cache enabled, the PHP engine has to accesses the script files on a file system. When PHP scripts are stored on a remote universal naming convention (UNC) file share, the file operations introduce a significant performance overhead. The Windows Cache Extension for PHP includes a file cache that is used to store the content of the PHP script files in shared memory, which reduces the amount of file system operations performed by PHP engine. Relative File Path Cache PHP scripts very often include or operate with files by using relative file paths. Every relative file path has to be converted to an absolute file path by the PHP engine. When a PHP application uses many PHP files and accesses them by relative paths, the operation of resolving relative paths to absolute paths may have a negative impact on the application’s performance. The Windows Cache Extension for PHP provides a relative file path cache, which is used to store the mappings between relative and absolute file paths, thereby reducing the number of relative path resolutions that the PHP engine has to perform.
  3. Consuming without WSDL and with WSDL
  4. definitions The definitions element must be the root element of all WSDL documents. It defines the name of the web service, declares multiple namespaces used throughout the remainder of the document, and contains all the service elements described here. types The types element describes all the data types used between the client and server. WSDL is not tied exclusively to a specific typing system, but it uses the W3C XML Schema specification as its default choice. If the service uses only XML Schema built-in simple types, such as strings and integers, the types element is not required. A full discussion of the types element and XML Schema is deferred to the end of the chapter. message The message element describes a one-way message, whether it is a single message request or a single message response. It defines the name of the message and contains zero or more message part elements, which can refer to message parameters or message return values. portType The portType element combines multiple message elements to form a complete one-way or round-trip operation. For example, a portType can combine one request and one response message into a single request/response operation, most commonly used in SOAP services. Note that a portType can (and frequently does) define multiple operations. binding The binding element describes the concrete specifics of how the service will be implemented on the wire. WSDL includes built-in extensions for defining SOAP services, and SOAP-specific information therefore goes here. service The service element defines the address for invoking the specified service. Most commonly, this includes a URL for invoking the SOAP service.