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 re开发者_如何学Pythonference to start with :(
Is there a guide on how to do something like this?
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.
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.
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.
精彩评论