从php调用F#(.net dll)代码

jle*_*ard 4 .net php com dll f#

我想知道是否有可能从php调用一些F#代码.看起来Phalanger就是这样做的.有人用吗?对于这个解决方案和其他解决方案(如果有的话?),它对服务器运行代码有什么要求?

谢谢

sha*_*mar 5

是的,您可以使用PHP COM类,但它仅适用于Windows版本的PHP5 +,无需单独安装.所以,你喜欢这样:

<?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;
?>
Run Code Online (Sandbox Code Playgroud)

如果你怀疑使用PHP COM类,然后读这PHP手册:

从PHP 5开始,这个扩展(和本文档)从头开始重写,并且已经删除了许多旧的混乱和伪造的错误.此外,我们还支持使用Microsoft提供的COM互操作性层实例化和创建.Net程序集.

本文显示了所做的所有更改.


Tom*_*cek 5

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:我与Phalanger有一段时间的关系,所以如果您有任何疑问,请告诉我 - 我可以将它们转发给当前的开发人员(如果您感兴趣,他们也可以提供一些商业支持).