What are the best options for connecting PHP apps to logic located in .NET libraries?
PHP, since v5.0, supports a DOTNET class that is supposed to let me invoke .NET logic from a PHP script. But it seems there are many problems - I've not been able to get it to work reliably, with arbitrary .NET classes. The doc is sort of slim and what is documented isn't really correct. The questions on the internets on this class are many, as are the bug reports on php.net.
I have been able to get PHP to connect with .NET via COM interop - but this requires that the .NET class be ComVisible. And as far as I know, because of the COM requirement, this works on Windows only.
I've heard of the Phalanger project but don't know many details. Does it work with arbitrary PHP scripts? Work on Linux? Does it have heavy perf or runtime implications?
Does it even make sense to do this, or is it one of those you-could-do-it-but-you-shouldn't sort of things?
EDIT: I'd like to hear about the general case: there is a wide variety of .NET class libraries available, and it would be nice to be able to take advantage of them from different environments, including PHP. Examples might be encryption, logging, data access, clients to HPC clusters. The particular immediate scenario is a ZIP library with AES encryption, available in .NET.
Microsoft doesn't ship or support .NET on Linux. If you wan't to run .NET code on Linux then you should look at Mono. I don't know if PHP 5 supports Mono as well as MicroSoft.NET
Using .net classes and calling .net methods from Phalanger is very easy, since it's PHP compiler for .NET. You can check this article PHP for .NET: Introduction for .NET developers, the article is older(2007) so there can be few out-of-date examples, but the principles applies.
On Linux Phalanger runs fine on Mono, the biggest limitation here is that you can't use native extensions (from PHP distribution), which are supported only on Windows (the extension manager in Phalanger is built with C++/CLI which isn't supported on Mono). But still you can use some managed extensions for Phalanger that are available.
The Performance of the Phalanger in actual version(February 2011 release) is around 2times faster than PHP 5.3.5 via FastCGI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With