栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Linux GCC上用C构建我的第一个PHP扩展?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Linux GCC上用C构建我的第一个PHP扩展?

此示例的扩展名。

<?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进行编译并获得测试扩展



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382824.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号