简体   繁体   English

从C调用PHP

[英]Calling PHP From C

I am trying to write an application that will use PHP as a scripting language. 我正在尝试编写一个将PHP作为脚本语言使用的应用程序。 The application is a CGI handler, and I want to be able to call PHP pages from it. 该应用程序是一个CGI处理程序,我希望能够从中调用PHP页面。

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. 我正在寻找可以让我在C程序中初始化PHP,然后将包含php代码或文件名的缓冲区传递给它进行解析的代码。 I want to take the output from that and be able to run it through a function in the CGI program. 我想从中获取输出并能够通过CGI程序中的函数运行它。

The book Extending and Embedding PHP by Sara Golemon ( amazon ) has a chapter about embedding PHP in a C programm, which might interest you. Sara Golemon amazon所著的《 扩展和嵌入PHP 》一书中有一章介绍了将PHP嵌入C程序,这可能会让您感兴趣。

If you want a preview, from what I remember, some pages are avaible on Google books, for instance. 根据我的记忆,例如,如果要预览,则可以在Google图书上找到一些页面。


Here's a quick quote (from the beginning of chapter 20.) : 快速报价(从第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. 如上一章所述,除了加载外部脚本外,PHP嵌入应用程序还可以使用实现熟悉的userspace eval()命令的基础函数来执行较小的任意代码片段。

Try the PHPEmbed library. 试试PHPEmbed库。 It's for C++, rather than C, but it might still work for you, depending on the project requirements. 它适用于C ++,而不是C,但仍可能对您有用,具体取决于项目要求。

I would check out how they've implemented the php command line binary. 我将检查他们如何实现php命令行二进制文件。 It seems the main function is in php_cli.c 似乎主要功能在php_cli.c中

And it calls php_execute_scrip and a bunch of other functions which looks promising. 它调用了php_execute_scrip和其他一些看起来很有前途的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM