没有服务器的 PHP

发布于 2024-11-14 20:24:02 字数 384 浏览 3 评论 0原文

我有一个 C# 应用程序,需要调用 PHP 脚本并以尽可能最快的方式获取输出。我探索的选项:

  • 使用 PHP CLI 执行脚本(优点:简单/缺点:无操作码缓存/预编译]
  • 编译 PHP(Phalanger、Hiphop 等)[优点:无 Web 服务器/缺点:兼容性]
  • 使用嵌入式 Web 服务器( AppWeb、Cherokee、Lighttpd)[优点:简单/缺点:部署]

还有其他选项吗?

编辑:最好的选择是使用通过运行 php-cgi.exe -b 127.0.0.1 构建 PHP 的 FastCGI 服务器,但似乎没有(C#)代码可以与可用的服务器通信。侧库(如 FCGIDotNet 和 SharpCGI),它们都实现了协议的服务器端。

I have a C# application that needs to call a PHP script, and get the output, in the fastest possible way. The options I explored:

  • Executing the script with PHP CLI (Pro: Easy / Cons: No Opcode Cache / Precompilation ]
  • Compiling the PHP (Phalanger, Hiphop, etc.) [Pro: No Webserver / Con: Compatibility ]
  • Using an embedded webserver (AppWeb, Cherokee, Lighttpd) [Pro: Simple / Cons: Deployment ]

Are there any other options left?

EDIT: The best possible option would be to make use of the build-in FastCGI server of PHP, by running php-cgi.exe -b 127.0.0.1. But there seems no (C#) code to talk to a server available. While there are so many server-side libraries (like FCGIDotNet and SharpCGI), they all implement the server-side of the protocol.

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

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

发布评论

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

评论(2

放血 2024-11-21 20:24:02

另一种选择可能是将 PHP CLI 脚本作为守护进程运行(关于此这里< /a>)。

如果脚本的启动/清理时间特别长,那么将其作为守护进程运行将意味着您只需执行一次。

缺点是您需要编写一种与该守护进程通信的方法,以将数据从 C# 获取到它。您还需要随着时间的推移密切关注其内存使用情况。

不过,最好的方法始终是针对您的脚本的。

One other option could be to run the PHP CLI script as a daemon (good blog post on this here).

If the script has a particularly long startup/cleanup, then running it as a daemon would mean that you only do this once.

The downside is that you'd need to write a way of communicating with that daemon, to get the data from C# to it. You'd also need to keep an eye out on its memory usage over time.

The best method is always going to be specific to your script though.

孤者何惧 2024-11-21 20:24:02

您可能知道,PHP 最初代表“个人主页”,现在据说代表“PHP:超文本预处理器”,字面上说明了它的用法,并且基本上,开发人员不会为了获得脚本选项而将其嵌入到其应用程序中。

除非你有一些非常具体的软件和强有力的论据,否则我建议你坚持使用 Lua,或者类似的脚本库,易于嵌入和维护。否则,请按照每个人都使用它的方式使用它,CLI。否则就要做好面对后果的准备。

As you may know, PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext Preprocessor", which literally states it's usage, and basically is not something that a developer would embed into his application just to have a scripting option.

Unless you have some really specific piece of software and strong arguments, I'd suggest you to stick to Lua, or similar scripting libraries which are easy to embed and maintain. Otherwise, use it the way as everyone is using it, CLI. Or else be prepared to face the consequences.

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