In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
本文小编为大家详细介绍"PHP拓展的实现手段有哪些",内容详细,步骤清晰,细节处理妥当,希望这篇"PHP拓展的实现手段有哪些"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
关于 PHP 扩展的几种实现手段
1.php 原生扩展开发 c 语言,注:【ext_skel.php】脚本创建
2.zephir
3.php-cpp
4.php-x
5.cgo
封装 zendapi 模式
CGO 嵌套 C 和 GO 代码,用 GO 去编译了 php 扩展骨架和 GO 的具体实现
等。。。不限上面几种方式。
围绕【zephir,cgo,PHP 开启 JIT】4 种模式下,通过斐波那契数列计算性能,来查看运行效果。
zephir 代码生成扩展
//Main 类final class Zimuge{ public static function calcFibonacci(int i){ if (i < 2) { return i; } return self::calcFibonacci(i - 1) + self::calcFibonacci(i - 2); }编译安装zephir build
cgo 代码生成扩展
package main/*#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_ini.h"#include "ext/standard/info.h"static int le_go2php;PHP_MINIT_FUNCTION(go2php){ return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(go2php){ return SUCCESS;}PHP_RINIT_FUNCTION(go2php){ return SUCCESS;}PHP_RSHUTDOWN_FUNCTION(go2php){ return SUCCESS;}PHP_MINFO_FUNCTION(go2php){ php_info_print_table_start(); php_info_print_table_header(2, "go2php support", "enabled"); php_info_print_table_end();}PHP_FUNCTION(go2php_print){ zend_long a,b; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(a) ZEND_PARSE_PARAMETERS_END(); b = calcFib(a); RETURN_LONG(b);}ZEND_BEGIN_ARG_INFO(null, 0)ZEND_END_ARG_INFO()const zend_function_entry go2php_functions[] = { PHP_FE(go2php_print, null) PHP_FE_END};zend_module_entry go2php_module_entry = { STANDARD_MODULE_HEADER, "go2php", go2php_functions, PHP_MINIT(go2php), PHP_MSHUTDOWN(go2php), PHP_RINIT(go2php), PHP_RSHUTDOWN(go2php), PHP_MINFO(go2php), "0.1.0", STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_GO2PHPZEND_GET_MODULE(go2php)#endif*/import "C"func main() {}package mainimport "C"//export calcFibfunc calcFib(i int) int { if i < 2 { return i } return calcFib(i-1)+calcFib(i-2)}
编译&链接
CGO_CFLAGS="-g \-I`/root/download/php8/bin/php-config --include-dir` \-I`/root/download/php8/bin/php-config --include-dir`/main \-I`/root/download/php8/bin/php-config --include-dir`/TSRM \-I`/root/download/php8/bin/php-config --include-dir`/Zend \-I`/root/download/php8/bin/php-config --include-dir`/ext \-I`/root/download/php8/bin/php-config --include-dir`/ext/date/lib \-DHAVE_CONFIG_H" CGO_LDFLAGS="-Wl,--export-dynamic -Wl,--unresolved-symbols=ignore-all" go build -p 1 -gcflags "-l" -buildmode=c-shared -o go2php.so
测试用 php 脚本代码
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.