首先是config.m4的内容
点击(此处)折叠或打开
- dnl
- dnl $Id: config.m4 72968 2002-03-12 16:44:00Z sas $
- dnl
- PHP_ARG_ENABLE(demo, [Whether to enable the "demo" extension], [ enable-demo Enable "demo" extension support])
- if test $PHP_DEMO != "no"; then
- PHP_SUBST(DEMO_SHARED_LIBADD)
- PHP_NEW_EXTENSION(demo, demo.c, $ext_shared)
- fi
php_walu.h写的不够完善,如此可能更好
点击(此处)折叠或打开
- //php_demo.h
- #ifndef DEMO_H
- #define DEMO_H
- //加载config.h,如果配置了的话
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- //加载php头文件
- #include "php.h"
- #define phpext_demo_ptr &demo_module_entry
- extern zend_module_entry demo_module_entry;
- #endif
点击(此处)折叠或打开
- //demo.c
- #include "php_demo.h"
- //module entry
- ZEND_FUNCTION(demo_hello)
- {
- php_printf("Hello World!\n");
- }
- ZEND_FUNCTION(demo_add)
- {
- long a;
- long b;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"ll",&a,&b) == FAILURE)
- {
- RETURN_NULL();
- }
- long c = a + b;
- RETVAL_LONG(c);
- }
- static zend_function_entry demo_functions[] = {
- ZEND_FE(demo_hello,NULL)
- PHP_FE(demo_add,NULL)
- {NULL,NULL,NULL}
- };
- zend_module_entry demo_module_entry = {
- #if ZEND_MODULE_API_NO >= 20010901
- STANDARD_MODULE_HEADER,
- #endif
- "demo", //这个地方是扩展名称,往往我们会在这个地方使用一个宏。
- demo_functions, /* Functions */
- NULL, /* MINIT */
- NULL, /* MSHUTDOWN */
- NULL, /* RINIT */
- NULL, /* RSHUTDOWN */
- NULL, /* MINFO */
- #if ZEND_MODULE_API_NO >= 20010901
- "2.1", //这个地方是我们扩展的版本
- #endif
- STANDARD_MODULE_PROPERTIES
- };
- #ifdef COMPILE_DL_DEMO
- ZEND_GET_MODULE(demo)
- #endif