html5-img
1 / 17

Integration between PHP and .NET Applications

Integration between PHP and .NET Applications. Svetlin Nakov. National Academy for Software Development. academy.devbg.org. Contents. PHP Interoperability PHP and COM Writing WordPress Plug-in in C# Phalanger: Running PHP in .NET CLR. PHP Interoperability. PHP Interoperability.

geoff
Télécharger la présentation

Integration between PHP and .NET Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Integration between PHP and .NET Applications Svetlin Nakov National Academy for Software Development academy.devbg.org

  2. Contents • PHP Interoperability • PHP and COM • Writing WordPress Plug-in in C# • Phalanger: Running PHP in .NET CLR

  3. PHP Interoperability

  4. PHP Interoperability • What is Interoperability? • Ability to work together with other products, frameworks, languages and platforms • PHP Interoperability • Call external process – shell_exec() function • Invoke native C/C++ code (.so / .dll libraries) • dl() function in PHP (load extension library) • SWIG – http://www.swig.org/ • COM operability (in Windows) • Web services (REST / SOAP)

  5. PHP and COM

  6. What is COM? • Component Object Model (COM) • Microsoft Windows built-in technology • Inter-process communication between components and applications • Example: Display Adobe Acrobat PDF in Internet Explorer • Object-oriented approach • Allows dynamic object creation and method invocation and properties / events access • Language-neutral technology

  7. Creating COM Component in .NET Framework and C# • Define the COM dispatch interface: • Define the COM implementation class: [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface ICalculator { int Sum(int a, int b) } namespace PlayingWithCOM { [ComVisible(true)] [Guid("38AADE7B-79B8-31A1-B365-22C6AAE5232C")] public class Calculator : ICalculator { public int Sum(int a, int b) { return a+b; } } }

  8. Register COM Component Assembly in the Registry • Sign the assembly with strong name: • Install the assembly in the Global Assembly Cache (GAC): • Register the assembly as COM component in Windows registry: [assembly:AssemblyKeyFile(@"secret-key.snk")] gacutil -i PlayingWithCOM.dll regasm PlayingWithCOM.dll

  9. Using COM Objects from PHP Script • Creating COM object and invoking method from PHP: $calc = newCOM("PlayingWithCOM.Calculator"); $result = $calc->Sum(5, 6); echo $result;

  10. Writing WordPress Plug-ins in C#

  11. WordPress on IIS • Running WordPress in IIS • Run PHP on IIS: • Install FastCGI ISAPI extension for IIS • Install and configure PHP for Windows • Alternatively use Web Platform Installer • Install and configure MySQL for Windows • Configure WordPress and URL rewriting: • ISAPI_Rewrite in IIS 5.1/6 • Microsoft URL Rewrite for IIS 7

  12. Creating WordPress Plug-in • We want to create WordPress plug-in for downloading a blog post as PDF document • Converting HTML page to PDF is not straightforward problem! • We prefer to implement this in C# • Use Internet Explorer through COM • Open the web page URL in Internet Explorer • Take the entire page as graphics image • Cut the image into pages and write them to PDF document with PdfSharp • Invoke the C# class from PHP through COM

  13. Creating WordPress Plug-in (2) • We want to add a parameter "?pdf" to all WordPress URLs to produce PDF output • We hook the WordPress action "init" • In the action handler invoke the C# based Web2Pdf converter add_action('init', 'init_action_handler'); $web2pdf = new COM("Web2Pdf.WebPageToPDFGenerator"); $pdf_base64 = $web2pdf->GeneratePdfFromWebPageAsBase64($url);

  14. Creating WordPress Plug-In in C# - Web2Pdf Converter Live Demo

  15. Phalanger The PHP Language Compiler for .NET

  16. Phalanger Project: Running PHP in .NET Framework • Phalanger Project • Open source PHP compiler for .NET CLR • Web site: http://www.php-compiler.net • Compiles PHP code to MSIL just like C# • Implements all standard PHP functions • Two modes of execution: • Classical PHP execution model – run existing applications like phpBB, Drupal, etc. • ASP.NET mode – use ASP.NET with PHP language – mix .NET and PHP functions

  17. Integration between PHP and .NET Applications Questions?

More Related