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

发布于 2024-09-17 06:20:42 字数 109 浏览 5 评论 0 原文

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼睛会笑 2024-09-24 06:20:42

是的,您可以通过使用 PHP COM 类,但是它仅适用于 PHP5+ 的 Windows 版本,无需单独安装。所以,您确实会这样做:

<?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;
?>

如果您对使用 PHP COM 类持怀疑态度,请从 阅读此内容 .net/manual/en/intro.com.php" rel="noreferrer">PHP 手册

从 PHP 5 开始,此扩展(以及此文档)从头开始重写,许多旧的令人困惑和虚假的内容已被删除。此外,我们还支持使用 Microsoft 提供的 COM 互操作层来实例化和创建 .Net 程序集。

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

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.

戏舞 2024-09-24 06:20:42

Phalanger 应该能够直接调用 F# 代码(就像任何其他已编译的 .NET 代码一样。该代码与使用标准 PHP 类型时的代码相同(尽管 Phalanger 具有允许您使用 .NET 特定事物(例如泛型)的扩展)使用 PHPCOM 可能会很棘手)。

从使用 Phalanger 编译的 PHP 站点运行 F# 代码的要求只是 .NET 2.0+ 和 IIS(对于 F#,您需要引用 F# 库和 )。 FSharp.Core.dll(包含 F# 运行时和基本类型)

PS:我参与 Phalanger 一段时间了,所以如果您有疑问,请告诉我 - 我可以将它们转发到当前版本。开发人员(如果您感兴趣,他们还可以提供一些商业支持)。

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

你又不是我 2024-09-24 06:20:42

Phalanger 似乎在其领域做得越来越好,并且由于它有效地使 PHP 成为一种 .NET 语言,因此它是与其他 .NET 语言互操作性的明显选择。尽管我可以想象,你的 PHP 代码需要进行相当多的更改。

如果这对你不起作用,那么我会同意上面 Max 的观点。使用WebService,如果在同一服务器上运行,它仍然会非常快,并且具有通过Mono和mod_mono仍然可以部署在Windows以外的其他服务器平台上的优点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文