1:我们先生成libphp7.so库.在编译的时候加上–enable-embed
wget http://cn2.php.net/distributions/php-7.0.11.tar.gz
tar -zxvf php-7.0.11.tar.gz
cd php-7.0.11
configure --enable-embed
make
make install
生成的libphp7.so文件应该在/usr/local/lib/目录下,需要的头文件应该在 /usr/local/include/php目录下.
2:编写C文件embed.c
#include "sapi/embed/php_embed.h"
int main(int argc, char * argv[]){
PHP_EMBED_START_BLOCK(argc,argv);
char * script = " print 'Hello World!';";
zend_eval_string(script, NULL,"Simple Hello World App" TSRMLS_CC);
PHP_EMBED_END_BLOCK();
return 0;
}
3:编译生成目标程序
gcc -I /usr/local/include/php/ -I /usr/local/include/php/main/ -I /usr/local/include/php/Zend/ -I /usr/local/include/php/TSRM/ -lphp7 -o embed embed.c
4:运行程序
现在我们大概可以了解php7的嵌入式开发了