How to develop C extensions for PHP apps?

前端 未结 3 1094
不知归路
不知归路 2020-12-16 07:38

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 s

相关标签:
3条回答
  • 2020-12-16 08:19

    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.

    0 讨论(0)
  • 2020-12-16 08:36

    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.

    0 讨论(0)
  • 2020-12-16 08:41

    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.

    0 讨论(0)
提交回复
热议问题