如何为 PHP 应用程序开发 C 扩展?

发布于 2024-09-04 07:31:45 字数 106 浏览 2 评论 0原文

我的 PHP 应用程序有一个数字运算部分,对于 PHP 来说速度很慢,所以我正在考虑构建一个自定义 C 扩展,但不可能找到任何好的参考来开始:(

有关于如何做的指南吗?像这样的东西?

My PHP app has a number-crunching part that is just to slow for PHP, so I was thinking of building a custom C extension, but it is impossible to find any good reference to start with :(

Is there a guide on how to do something like this?

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

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

发布评论

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

评论(3

浮生未歇 2024-09-11 07:31:45

最好的资源是 扩展和嵌入 PHP,作者:Sara Golemon。更过时的是 PHP 文档。另一方面,PHP wiki 上的内容非常最新,但也相当不完整并且不太适合初学者。另请参阅这些文章高级 PHP 编程,作者:George Schlossnagle,PHP 编程,作者:Rasmus Lerdorf 和 Kevin Tatroe,特别是 这些幻灯片

最后,您会找到的最权威的来源是 源代码 与 PHP 捆绑的扩展。

The best resource, although outdated in several aspects (it only covers PHP until version 5.1) is Extending and Embedding PHP by Sara Golemon. Even more outdated is the PHP documentation. On the other hand, the content on the PHP wiki is very up-to-date, but also quite incomplete and not very oriented for beginners. See also these articles, part V of Advanced PHP Programming by George Schlossnagle, chapter 14 of Programming PHP by Rasmus Lerdorf and Kevin Tatroe and, specially, these slides.

Finally, the most authoritative source you'll find is the source code of the extensions bundled with PHP.

爱给你人给你 2024-09-11 07:31:45

这可能不是一个答案,而更像是一个建议,有一些工具可以将你的 php 编译为可执行文件,然后你可以将其用作扩展。这会稍微统一您的代码并统一您的项目。我不久前尝试过类似的事情。编译后的 php 的行为与编译后的 c 没有什么不同。

This might not be an answer but more like a suggestion, There are tools out there to compile your php to an executable, which you could just then use as an extension. This Would uniform your code a bit and unify your project. I have tried something like this a while ago. The compiled php acts no differently than the compiled c would.

总攻大人 2024-09-11 07:31:45

另一种选择是用 C 编写的命令行工具,您可以从 PHP 启动并通过 stdin/stdout 进行通信。在许多情况下,这更容易编写和部署,但最终取决于您的用例。

Another option would be a command line tool written in C, that you start from PHP and communicate with over stdin/stdout. In many cases this is much easier to write and to deploy, but it ultimately depends on your use case.

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