tags:

views:

90

answers:

3

Hello,

I was wondering if it was possible to call some F# code from php. It seems like Phalanger does the trick. Is anybody using it ? For this solutions and others( if there are any?), what requirements does it have on the server to run the code ?

Thank you

+2  A: 

Yes you can, by using PHP COM class but it works only on Windows version of PHP5+ and needs no separate installation. So, you do like this:

<?php
$obj = new COM("myfsharp.dll");

$output=$obj->HelloWorld(); // Call the "HelloWorld()" method from the DLL.
// once we created the COM object this can be used like any other php classes.
echo $output;
?>

And if you're skeptical about using PHP COM class, then read this from the PHP Manual:

Starting with PHP 5, this extension (and this documentation) was rewritten from scratch and much of the old confusing and bogus cruft has be removed. Additionally, we support the instantiation and creation of .Net assemblies using the COM interoperability layer provided by Microsoft.

This article shows all the changes done.

shamittomar
@shamittomar thanks, Ill give it a try
jlezard
+2  A: 

Phalanger should be able to call F# code directly (just like any other compiled .NET code. The code would be the same as when working with standard PHP types (although Phalanger has extensions that allow you to use .NET specific things like generics - which could be tricky using PHPCOM).

The requirements to run F# code from PHP site compiled using Phalanger are just .NET 2.0+ and IIS (to host the web site). For F#, you would need to reference your F# library and FSharp.Core.dll (which contains F# runtime and basic types).

PS: I was involved with Phalanger for some time, so if you have questions, let me know - I can forward them to the current developers (they can also provide some commercial support if you were interested).

Tomas Petricek
@Tomas thanks! I'll shout for help if I come to use Phalanger
jlezard
A: 

Phalanger appears to be getting better at what it does and as it effectively makes PHP a .NET language, it is an obvious choice for interoperability with other .NET languages. Quite a few changes to your PHP code though I would imagine.

If that does not work for you, then I would agree with Max above. Use a WebService, if operating on the same server it would still be pretty quick and has the advantage that via Mono and mod_mono could still be deployed on other server platforms than Windows.

Orbling