Wednesday, September 5, 2007

Phalanger PHP language Compiler for the .NET platform

Phalanger overview

Phalanger is a new PHP implementation introducing the PHP language into the family of compiled .NET languages. It provides PHP applications an execution environment that is fast and extremely compatible with the vast array of existing PHP code. Phalanger gives web-application developers the ability to benefit from both the ease-of-use and effectiveness of the PHP language and the power and richness of the .NET platform taking profit from the best from both sides.

Phalanger and existing PHP applications

Phalanger provides PHP language and standard library implementation that is compatible with most of the existing PHP applications including many large open source PHP projects (see Phalanger apps section for more details). Phalanger compiles PHP scripts into MSIL (Microsoft Intermediate Language) which can be executed by .NET or Mono runtime. This runtime executes MSIL code using JIT (Just-In-Time) compilation, which makes the execution far more effective than interpretation and significantly improves application speed.

As part of Phalanger project we also implemented standard PHP library functions (for example string and array manipulation etc). These functions are reimplemented using managed language (mostly C#) and have very good performance. Thanks to the managed code the implementation is also more secure and the security can be configured using standard .NET tools. Phalanger also supports calling native PHP4 extensions which makes it possible to use most of the PHP functions and classes.

Phalanger is using the ASP.NET framework internally, but only for implementing HTTP request and respons handling, sessions and cookies. The page rendering is still the same as in PHP which gives you full control over the generated code and also compatibility with existing PHP applications.

Enabling PHP to use .NET classes

Starting with the 2.0 version, Phalanger supports full interoperability with .NET. This means that you can access almost any .NET classes (written in C#, VB.NET and other managed languages) from your PHP applications. This requires adding several features to the PHP language that allows you to use .NET features like namespace (which are used to organize .NET classes) and generics (used for specifying type parameters of methods and classes). These language extensions are called PHP/CLR and are designed to retain dynamic PHP behavior (for more details see PHP/CLR Language Extensions).

Thanks to the PHP/CLR extensions you can easilly integrate existing PHP and ASP.NET applications, or use classes available for .NET Framework in your PHP application. This gives you for example the possibility to modify open-source PHP applications to use the standard ASP.NET 2.0 Membership (user management) system, which is very powerfull option for integrating web applications.

You can also develop new applications using PHP with the PHP/CLR language extensions and combine PHP and other .NET languages (for example C#) in one project. This gives you the possibility to leverage of the C# strictness in the application logic layer where the safety and strict object orientation is important, but use the simplicity and efficiency of PHP language for developing the presentation layer.

Developing .NET/Mono applications or libraries with PHP

Thanks to the full .NET/Mono support it is also possible to develop all kinds of .NET applications using PHP language. This includes applications with Windows Forms/Gtk# user interface, class libraries and web applications build using the ASP.NET infrastructure. This allows you to develop ASP.NET style applications which benefits from the ASP.NET features like code separation using code-behind, ASP.NET controls (including any third-party controls) and other. You can use this Phalanger project for smoothly porting PHP applications to the ASP.NET infrastructure, because you can make the original PHP application a part of a larger ASP.NET system, but still write all the source code in the PHP language.

Using this option you can also compile existing PHP projects to standard .NET assembly and use it in any .NET application. Using this technique you can use many of the very usefull and publicly available PHP projects in .NET as well. Phalanger contains two different compilation modes - the first mode (called legacy) is fully compatible with standard PHP and you can use it for compiling any PHP scripts, however using PHP scripts compiled in legacy mode is a bit more difficult. To make using PHP objects from C# as simple as possible we also introducted pure mode in which you have to follow a few additional rules (like specifying all source files during the compilation instead of using includes), but it gives you full .NET interoperability, which means that you can use class written in PHP directly from C#!

The possibility of developing fully .NET/Mono compatible application using PHP language is demonstrated on the attached screenshot where you can see Gtk# application written in PHP running on Fedora Core 6. You can visit the Tutorials section of this page for more examples including Windows Forms and ASP.NET applications.

Visual Studio Integration

Visual Studio supports the integration of additional languages into the editor using the VSIP (Visual Studio Integration Package). Thanks to this possibility we were able to implement Visual Studio extensions for PHP developers. This extensions includes wide range of project templates including Legacy PHP Application, Windows Forms Phalanger Application, ASP.NET Application written in PHP and many other.

Syntax highlighting for PHP source files is a must-have for every IDE and we’re working on support for InteliSense as well. You can also use the Visual Studio debugger for finding bugs in your PHP applications (running on Phalanger). The debugger allows you to set breakpoints in the source code, step through the code and view values of variables, however we are still working on improving the full VS.NET support.

Requirements

Phalanger runs on Microsoft .NET and Mono. If you want to use it with .NET you’ll need Microsoft .NET Framework 2.0 (which runs on Microsoft Windows 2000/XP/2003/Vista) and optionally Internet Information Services (IIS) with ASP.NET installed for hosting Phalanger web applications. For Mono, we recommend using the latest Mono package and optinally Apache web server with configured Mono support (using mod-mono). To benefit from the additional Visual Studio integration feature a Microsoft Visual Studio 2005 is required (Express editions of Visual Studio unfortunately can’t be supported because of licensing limitations).

Phalanger Features

Makes PHP first-class citizen in the .NET languages family

  • Compiles PHP language to the MSIL (Microsoft Intermediate Language), which is a byte-code assembly used by the .NET CLR
  • Allows using .NET objects from the PHP language thanks to the PHP/CLR Language Extensions
  • Enables using libraries written in PHP from other .NET languages

Compiles existing PHP applications to improve execution speed

  • Compiles many existing PHP applications (see Phalanger apps)
  • Improves execution speed thanks to the compilation and use of JIT (Just-In-Time) compilation
  • Implements standard PHP library functions and allows calling native PHP4 extensions using unmanaged code

Extends PHP with useful PHP/CLR extensions

  • PHP/CLR makes it possible to fully integrate PHP application with the .NET type system
  • It is possible to import namespaces as well as use namespaces in new PHP/CLR projects
  • Allows using .NET generics including writing and extending generic objects in the PHP language
  • Supports .NET custom attributes, partial classes, .NET properties and other important features

Creating .NET libraries in the PHP language

  • Compiles PHP scripts directly to the .NET/Mono assemblies
  • Allows writing objects fully compatible with .NET languages (like C#) in the pure mode
  • Allows calling functions written in PHP and working with PHP objects in the legacy mode

Using .NET libraries in PHP projects

  • Thanks to Phalanger you can use PHP for developing presentation layer on top of bussines logic written in C#
  • Phalanger makes it possible to use any .NET object in PHP applications
  • You can use ASP.NET 2.0 Membership for integrating user accounts in PHP and ASP.NET application

Integrates the PHP language into Microsoft Visual Studio

  • Provides project templates for developing Phalanger applications in Visual Studio
  • Supports syntax highlighting for PHP source files
  • Supports debugging of PHP applications running on Phalanger

No comments:

About Me

Ordinary People that spend much time in the box
Powered By Blogger