没有服务器的 PHP
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种选择可能是将 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.
您可能知道,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.