简体   繁体   English

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

[英]Calling F# (.Net dll) code from php

I was wondering if it was possible to call some F# code from php. 我想知道是否有可能从php调用一些F#代码。 It seems like Phalanger does the trick. 看起来Phalanger就是这样做的。 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. 是的,您可以使用PHP COM类,但它仅适用于Windows版本的PHP5 +,无需单独安装。 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 : 如果您对使用PHP COM持怀疑态度PHP手册中 阅读

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. 从PHP 5开始,这个扩展(和本文档)从头开始重写,并且已经删除了许多旧的混乱和伪造的错误。 Additionally, we support the instantiation and creation of .Net assemblies using the COM interoperability layer provided by Microsoft. 此外,我们还支持使用Microsoft提供的COM互操作性层实例化和创建.Net程序集。

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). Phalanger应该能够直接调用F#代码(就像任何其他已编译的.NET代码一样。代码与使用标准PHP类型时的代码相同(尽管Phalanger具有允许您使用特定于.NET的特定内容的扩展 - 使用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). 使用Phalanger编译的PHP站点运行F#代码的要求只是.NET 2.0+和IIS(托管网站)。 For F#, you would need to reference your F# library and FSharp.Core.dll (which contains F# runtime and basic types). 对于F#,您需要引用您的F#库和FSharp.Core.dll (其中包含F#运行时和基本类型)。

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

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. Phalanger在它的功能方面看起来越来越好,因为它有效地使PHP成为.NET语言,它是与其他.NET语言互操作的明显选择。 Quite a few changes to your PHP code though I would imagine. 尽管我想象你的PHP代码有很多变化。

If that does not work for you, then I would agree with Max above. 如果这对你不起作用,那么我同意Max的观点。 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. 使用WebService,如果在同一台服务器上运行,它仍然会很快,并且具有通过Mono和mod_mono仍然可以部署在除Windows之外的其他服务器平台上的优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM