1,C源码
#include "php.h"
ZEND_FUNCTION(hello);
zend_function_entry hellomodule_functions[] =
{
ZEND_FE(hello, NULL)
{NULL, NULL, NULL}
};
zend_module_entry hellomodule_module_entry =
{
STANDARD_MODULE_HEADER,
"Hello Module",
hellomodule_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};
#if COMPILE_DL_FIRST_MODULE
ZEND_GET_MODULE(hellomodule)
#endif
ZEND_FUNCTION(hello)
{
RETURN_STRING("HELLO WORLD",1);
}
2,makefile
HOM_PHP=/opt/TrendMicro/MinorityReport/php/include/php
PHP_INC=-I$(HOM_PHP) -I$(HOM_PHP)/include -I$(HOM_PHP)/Zend -I$(HOM_PHP)/TSRM -I$(HOM_PHP)/main
CFLAG=-fpic -DCOMPILE_DL_FIRST_MODULE=1 -Wall
LFLAG = -shared
all:
gcc $(CFLAG) $(PHP_INC) -c -o hello.o hello.c
gcc $(LFLAG) -o hello.so hello.o
clean:
rm -rf *.o *.so
3,配置
mv hello.so php/ext
添加 extension=hello.so 到php.ini中
4,,验证
php -r 'echo hello();‘
参考: