Calling PHP From C

限于喜欢 提交于 2019-12-30 05:27:11

问题


I am trying to write an application that will use PHP as a scripting language. The application is a CGI handler, and I want to be able to call PHP pages from it.

I am looking for code that will let me initialize PHP inside the C program and then pass it either a buffer containing the php code, or a filename, for it to parse. I want to take the output from that and be able to run it through a function in the CGI program.


回答1:


The book Extending and Embedding PHP by Sara Golemon (amazon) has a chapter about embedding PHP in a C programm, which might interest you.

If you want a preview, from what I remember, some pages are avaible on Google books, for instance.


Here's a quick quote (from the beginning of chapter 20.) :

In addition to loading external scripts, as you saw in the last chapter, your PHP embedding application can also execute smaller snippets of arbitrary code using the underlying function that implements the familiar userspace eval() command.




回答2:


Try the PHPEmbed library. It's for C++, rather than C, but it might still work for you, depending on the project requirements.




回答3:


I would check out how they've implemented the php command line binary. It seems the main function is in php_cli.c

And it calls php_execute_scrip and a bunch of other functions which looks promising.



来源:https://stackoverflow.com/questions/1902409/calling-php-from-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!