开发者

Calling F# (.Net dll) code from php

I 开发者_JS百科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


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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜