此示例的扩展名。
<?php function hello_world() { return 'Hello World'; }?>config.m4
PHP_ARG_ENABLE(hello, whether to enable HelloWorld support,[ --enable-hello Enable Hello World support])if test "$PHP_HELLO" = "yes"; then AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World]) PHP_NEW_EXTENSION(hello, hello.c, $ext_shared)fi
php_hello.h
#ifndef PHP_HELLO_H#define PHP_HELLO_H 1#define PHP_HELLO_WORLD_VERSION "1.0"#define PHP_HELLO_WORLD_EXTNAME "hello"PHP_FUNCTION(hello_world);extern zend_module_entry hello_module_entry;#define phpext_hello_ptr &hello_module_entry#endif
#### 你好ç
#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_hello.h"static function_entry hello_functions[] = { PHP_FE(hello_world, NULL) {NULL, NULL, NULL}};zend_module_entry hello_module_entry = {#if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER,#endif PHP_HELLO_WORLD_EXTNAME, hello_functions, NULL, NULL, NULL, NULL, NULL,#if ZEND_MODULE_API_NO >= 20010901 PHP_HELLO_WORLD_VERSION,#endif STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_HELLOZEND_GET_MODULE(hello)#endifPHP_FUNCTION(hello_world){ RETURN_STRING("Hello World", 1);}构建扩展 $ phpize $ ./configure –enable-hello $ make
运行完这些命令后,您应该有一个hello.so
将extension = hello.so扩展到您的php.ini以触发它。
php -r 'echo hello_world();'
你完成了。;-)
在这里阅读更多
一种简单的方法,只需尝试使用zephir-lang即可以更少的知识来构建php扩展
namespace Test;class Hello{ public function say() { echo "Hello World!"; }}使用zephir进行编译并获得测试扩展



